F
Florian A.
Hi everyone!
I'm trying to write a global hook in C# and C++/CLI. I'm almost
done if there wasn't this little delegate problem.
I get the function pointer to a delegate and pass it to my
hook.dll. The delegate gets called for a few seconds but then the delegate
seems to be relocated on the CLR heap.
If tried using a GCHandle but as far as I can tell this only
prevents the garbage collector from collecting my delegate and doesn't stop
relocation.
Then there is pin_ptr. But a pinning pointer only works till it
goes out of scope and it can only be declared locally so this happens
immediately after I get the function pointer. By the way, I use ...
proc =
(HOOKPROC)(Marshal::GetFunctionPointerForDelegate(innerEventHandler).ToPointer());
... to get the function pointer.
If anyone knows how to pin the delegate for as long as I need to
point to it from unmanaged code or has any ideas, workarounds, etc. please
let me know!
Thank you very much in advance!
Regards,
Florian
I'm trying to write a global hook in C# and C++/CLI. I'm almost
done if there wasn't this little delegate problem.
I get the function pointer to a delegate and pass it to my
hook.dll. The delegate gets called for a few seconds but then the delegate
seems to be relocated on the CLR heap.
If tried using a GCHandle but as far as I can tell this only
prevents the garbage collector from collecting my delegate and doesn't stop
relocation.
Then there is pin_ptr. But a pinning pointer only works till it
goes out of scope and it can only be declared locally so this happens
immediately after I get the function pointer. By the way, I use ...
proc =
(HOOKPROC)(Marshal::GetFunctionPointerForDelegate(innerEventHandler).ToPointer());
... to get the function pointer.
If anyone knows how to pin the delegate for as long as I need to
point to it from unmanaged code or has any ideas, workarounds, etc. please
let me know!
Thank you very much in advance!
Regards,
Florian