Win32 function vs delegate issues with api
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Sep 8 19:20:23 PDT 2015
On 09/09/15 12:18 PM, Prudence wrote:
> I have
>
> hook = SetWindowsHookEx(WH_MOUSE, &Proc, NULL, ThreadID);
>
> Proc is the standard hook proc:
>
> public extern (Windows) LRESULT Proc(int code, WPARAM wParam, LPARAM
> lParam)
>
> I get a type mismatch because Proc is a delegate and SetWindowsHookEx
> expects a function. Making proc static works but not the behavior I want
> since all this stuff is wrapped in a class.
>
> Is there any way to pass Proc to SetWindowsHookEx without issues of GB
> and such?
>
>
>
> Error: function windows.winuser.SetWindowsHookExA (int, extern (Windows)
> int function(int, uint, int), void*, uint) is not callable using
> argument types (const(int), extern (Windows) int delegate(int code, uint
> wParam, int lParam), void*, uint)
>
> I could cast Proc to a function, obviously, but I'll loose the delegate
> behavior and create problems when I try to use this inside Proc?
You have the ability to store some user info along with the pointer.
Store an integer. Use a global (private) array to map the integer to the
actual delegate. Use a free function as the proc function.
Of course, that has some indirection thats to the lookup. You could if
able to rewrite as the free-function and pass in the class as user data,
you could be smart about it ;)
https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/window.d#L384
https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/window.d#L401
More information about the Digitalmars-d-learn
mailing list