I have a DLL that I inject into another process but I want to be able to call the exports on that DLL from my application. I’ve read elsewhere that you have to the SendMessage API but I have no idea what to do. Is there any example code on how this is done?
Share
You can’t directly call functions in another process, in general. There are, however, some workarounds you can use.
First, if you know the address of the export (which isn’t the case a lot of the time), and the function you call uses the
__stdcallcalling convention, takes a pointer-sized integer as an argument, and returns a DWORD, you can useCreateRemoteThreadto execute it in a thread in the remote process. This is often used to runLoadLibraryto inject a DLL into a target process, sinceLoadLibraryis loaded in the same address on all processes on a given computer.Otherwise, the DLL you inject will need to do some sort of RPC with the process that called it. For example, you could have your injected DLL spawn a thread in its DLL_PROCESS_ATTACH handler, which in turn connects to a named pipe, or connects over COM or something to the master process.