Suitable IPC between a C++ DLL (local hooks) and C# application


Whats the best inter-process communication for a C++ DLL that's injected into a third-party process and a C# application? Here's the current situation:

// This gets executed within the target process memory region
LRESULT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam)
    if (code > 0)
        auto csharpApplicationFunctionPointerAddress = 0xdeadbeef;
        auto csharpApplicationFunctionResult = call csharp function with N parameters here

        // Do something with the result
        if (csharpApplicationFunctionResult == "foo")

    return CallNextHookEx(hookInstance, code, wParam, lParam);

I've come across this and figured out I'd need a RPC, however I can't seem to find the best suitable RPC for this problem, as that communication requires passing N parameters and getting the result back as fast as possible.


  1. Sockets are out of mind as I dont want to deal with timeouts
  2. Would named pipes work here or it's only advisable for string messages?(serialization/deserialization is out of mind)
  3. I do not want to use message polling with a remote thread, as this uses too much CPU

Are even there any options left? Feel free to correct me the notes above.

asked on Stack Overflow Mar 5, 2021 by Henri

1 Answer


I ended up creating an invisible dummy window to serve as a central point for receiving messages through SendMessage calls from the DLL.

answered on Stack Overflow Apr 6, 2021 by Henri

User contributions licensed under CC BY-SA 3.0