question

Jack-31 avatar image
0 Votes"
Jack-31 asked RLWA32-6355 answered

How to call functions in a DLL that is currently load in another process?

My question is the same as this one:
https://stackoverflow.com/questions/6631357/calling-functions-in-a-dll-loaded-by-another-process


I'm trying to call the Test function that is currently on a DLL load in a different process.

 BOOL APIENTRY DllMain(HMODULE hModule,
  DWORD  ul_reason_for_call,
  LPVOID lpReserved
 )
 {
  OutputDebugStringW(L"Loading Library...");
  switch (ul_reason_for_call)
  {
  case DLL_PROCESS_ATTACH:
  case DLL_THREAD_ATTACH:
  case DLL_THREAD_DETACH:
  case DLL_PROCESS_DETACH:
  break;
  }
  return TRUE;
 }

 extern "C" __declspec(dllexport) LPCWSTR Test()
 {
  DWORD pid= GetCurrentProcessId();

WCHAR buf[255];
wsprintf(buf, L"Current PID: %d", pid);
OutputDebugString(buf);

  return std::to_wstring(pid).c_str();
 }



I already learned how to do an IPC mechanism using SendMessage and a window that can handle the messages received.

I'm trying to understand the other options described in that post, like CreateRemoteThread or named pipe.
Would like to ask if someone could share a working example for this use case.

c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is How to receive a message containing WM_COPYDATA? your question? Because if is then asking this more general question is where you should have started. CreateRemoteThread is not an IPC. Note that that other question did not originally state it is for a DLL; for a DLL it is not necessary to create a window.




0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered

You can read about pipes and refer to Microsoft sample code for pipe servers and a pipe client -

Pipes (Interprocess Communications)

Using Pipes


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.