I have C++ DLL, that implements CTB_HOOK and c# app, from which I P/Invoke this DLL.
The system calls the function below when messages to hooked thread are intercepted (before activating, creating, destroying, minimizing, maximizing, moving, or sizing a window and so on). I want to pass nCode
to my c# application.
static LRESULT CALLBACK CBTHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_ACTIVATE)
{
MessageBox(NULL, TEXT("HCBT_ACTIVATE"), TEXT("inside hook"), MB_OK);
}
//here I want to pass nCode(code of intercepted message) to my c# app.
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
At first tried to use a callback
to C# from C++ code (good article on this topic). But soon I've realized I have no way to a pass pointer to c#_callback_function
to CBTHookProc
(I wanted to save pointer to c#_callback_function
as a global variable, but since each process using a DLL has its own instance of all the DLLs global nothing succeeded).
Then I googled for DLL share data, but I is only suitable for static variables.
So, is there a way to callback from hook procedure? Or maybe some other way to get data from hook procedure?