[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct TBBUTTON
{
public Int32 iBitmap;
public Int32 idCommand;
public byte fsState;
public byte fsStyle;
public byte bReserved1;
public byte bReserved2;
public UInt32 dwData;
public IntPtr iString;
};
const int BUFFER_SIZE = 0x4096;
var localBuffer = new byte[BUFFER_SIZE];
UInt32 processId;
var tbButton = new TBBUTTON();
IntPtr hDesktop = User32.GetDesktopWindow();
IntPtr hTray = User32.FindWindowEx( hDesktop, IntPtr.Zero, "Shell_TrayWnd", null );
IntPtr hReBar = User32.FindWindowEx(hTray, IntPtr.Zero, "TrayNotifyWnd", null);
IntPtr hTask = User32.FindWindowEx(hReBar, IntPtr.Zero, "SysPager", null);
IntPtr hToolbar = User32.FindWindowEx( hTask, IntPtr.Zero, "ToolbarWindow32", null );
UInt32 threadId = User32.GetWindowThreadProcessId(hToolbar, out processId);
IntPtr hProcess = Kernel32.OpenProcess(ProcessRights.ALL_ACCESS, false, processId);
IntPtr ipRemoteBuffer = Kernel32.VirtualAllocEx(hProcess, IntPtr.Zero, new UIntPtr(BUFFER_SIZE),
MemAllocationType.COMMIT, MemoryProtection.PAGE_READWRITE);
fixed (TBBUTTON* pTBButton = &tbButton)
{
var ipTBButton = new IntPtr(pTBButton);
var b = (int) User32.SendMessage(hToolbar, TB.GETBUTTON, (IntPtr) 1, ipRemoteBuffer);
bool b2 = Kernel32.ReadProcessMemory(hProcess, ipRemoteBuffer, ipTBButton,new UIntPtr((uint) sizeof(TBBUTTON)), IntPtr.Zero);
Console.WriteLine(tbButton.dwData + " dwData" );
}
Καλησπέρα σε όλους , έχω ένα πρόβλημα με τον συγκεκριμένο κώδικα πιο πάνω.
Το πρόβλημα είναι ότι ο κώδικας τρέχει σωστά σε Windows ΧΡ x86 αλλα όχι σε Vista x64 .
Σε windows ΧΡ μπορώ να εκτυπώσω το tbButton.dwData από το TBBUTTON struct κανονικά για κάθε button
από το toolbar, ενώ αντίθετος στα Vista x64 , πάντα είναι 0x00000...