I have a WPF application that needs to interface with another application.
This application has about 20 custom Windows Messages (WM_USER+50...WM_USER+70).
Summary of what I'm trying to accomplish:
WPF Application -> SendMessage -> ThirdParty application
The problem I have is that all of the Messages are CUSTOM messages. Therefore I have to implement my own data marshaling.
See http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
It seems that the process I need to go through is:
Grab the process and open it for all access. User32.GetWindowThreadProcessId(windowHandle, out pId);
// Open the process with all access
someprocess = OpenProcess((0x1F0FFF), false, (int)pId);Allocate a buffer in the process: IntPtr buffer = VirtualAllocEx( hProcess, IntPtr.Zero, 1024, 0x1000, 0x04 );
Fill up some sort of struct that will be written to the buffer created in #2?
Copy #3 to the remote buffer is #2? WriteProcessMemory??
Send the custom message ( SendMessage(windowhandle, customMsg, 0, buffer from #2?)
Read the struct back in from the remote process buffer into a local buffer
Marshal this data to a managed type. (This is a C# .Net application)
I could really use some insight. I haven't had much luck thus far. I think the part that I'm most stuck on is what type of struct to send to the WriteProcessMemory?