TB_GETBUTTONINFO does not work on Windows 7

I have a code like this:

TBBUTTONINFO mtbbi; HWND hwnd; HANDLE hProc; DWORD dwProcessID; void* lpData; 

.....

 GetWindowThreadProcessId(hwnd, &dwProcessID); hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, dwProcessID); lpData = VirtualAllocEx(hProc , 0, sizeof(TBBUTTONINFO), MEM_COMMIT, PAGE_READWRITE); memset(&mtbbi,0,sizeof(mtbbi)); mtbbi.cbSize=sizeof(TBBUTTONINFO); mtbbi.dwMask=TBIF_BYINDEX|TBIF_LPARAM; WriteProcessMemory(hProc,lpData,&mtbbi,sizeof(TBBUTTONINFO),&dwBytesRead); SendMessage(hwnd, TB_GETBUTTONINFO, 0, (LPARAM)lpData); ReadProcessMemory(hProc, lpData, &mtbbi, sizeof(TBBUTTONINFO), &dwBytesRead); 

where hwnd is the toolbar handle. This handle is valid, other messages (e.g. TB_BUTTONCOUNT or TB_GETBUTTON ) work fine. So, this code works correctly on Windows XP, but when I try to run it on Windows 7 x64, SendMessage returns -1, which means an error. I tried to use GETBUTTONINFOA instead of GETBUTTONINFO , but the result is the same.

What am I doing wrong?

+1
source share
2 answers

I decided. The problem was that the TBBUTTONINFO structure contains pointers that take a double size in 64-bit processes. I created my own structure by replacing pointers with int64, and SendMessage works properly with this structure. Thank you all for your help.

+3
source

Starting with Windows Vista, user interface privilege protection provides restrictions for a system that prohibits applications with a lower privilege from sending messages in a window or setting hooks in processes with higher privileges. However, applications with higher privileges are still allowed to send window messages to processes with lower privileges. These restrictions are implemented by throw SendMessage and other message sending functions.

I am not sure if this is the cause of your problem, because in general a read-only message is not blocked even from processes with lower privileges. Your TB_GETBUTTONINFO seems like a message like for TB_BUTTONCOUNT and TB_GETBUTTON . However, you should study this.

For more information, see Windows Integrity Mechanism Design .

+1
source

Source: https://habr.com/ru/post/1303916/


All Articles