GetMenuItemInfo access violation in user32.dll
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: GetMenuItemInfo access violation in user32.dll

  1. #1
    Join Date
    Mar 2004
    Posts
    1

    GetMenuItemInfo access violation in user32.dll

    when accessing from another thread.

    void getMenuItem(HWND hWndMenu)
    {
    HMENU menu = GetMenu(hWndMenu);
    MENUITEMINFO mi, *_mi; unsigned long pid;
    HANDLE process;

    GetWindowThreadProcessId(hWndMenu, &pid);
    process=OpenProcess (PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
    _mi=(MENUITEMINFO*)VirtualAllocEx(process, NULL, sizeof(MENUITEMINFO), MEM_COMMIT, PAGE_READWRITE);

    ZeroMemory(&mi, sizeof(MENUITEMINFO));

    mi.cbSize = sizeof(MENUITEMINFO);
    mi.fMask = MIIM_TYPE;
    mi.fType = MFT_STRING;
    mi.dwTypeData=NULL;
    WriteProcessMemory(process, _mi, &mi, sizeof(MENUITEMINFO), NULL);
    // this fails GetMenuItemInfo(menu, 1, true, _mi);
    ReadProcessMemory(process, _mi, mi, sizeof(MENUITEMINFO), NULL);
    int size = mi.cch;
    VirtualFreeEx(process, _mi, 0, MEM_RELEASE);

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392
    Are you sure all your handles (HWMD hWndMenu, HMENU menu, HANDLE process,...) are not NULL and valid?
    You must check all of them before trying to use!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center