Article View: borland.public.cppbuilder.nativeapi
Article #10576Re: Extracting menu name from another process
From: Ed Mulroy [TeamB]
Date: Mon, 05 Apr 2004 18:01
Date: Mon, 05 Apr 2004 18:01
43 lines
2038 bytes
2038 bytes
You might check the return value from the calls to VirtualAllocEx and
WriteProcessMemory.
. Ed
> jp wrote in message
> news:406c9e67$1@newsgroups.borland.com...
>
> Gives an access violation in user32.dll
>
> 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);
Technical Details
Message-ID:
<40719f19$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<406c9e67$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,9000e433ab0a74c6 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-04-05 11:10:22 PST From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <406c9e67$1@newsgroups.borland.com> Subject: Re: Extracting menu name from another process Date: Mon, 5 Apr 2004 14:01:36 -0400 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <40719f19$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1081188121 24.74.175.102 (5 Apr 2004 11:02:01 -0800) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail