So I've been contemplating if it is possible to use a delegate in to a PInvoke signature when the signature calls for a handle to a window (Such as in AddClipboardFormatListener(IntPtr hwnd)
).
I ask because essentially all it does is makes a call to said windows HwnProc method....So what if I made a delegate like this:
public delegate IntPtr MainWindowProc(IntPtr hwnd, int msg,
IntPtr wParam, IntPtr lParam, ref bool handled)
and changed AddClipboardFormatListener
to look like this instead:
AddClipboardFormatListener(MainWindowProc theDelegate)
I got the idea from SetWindowsHookEx
where I made a delegate for the callback for the second parameter. I'm fixing to wire up a test for this right now, so I might be answering my own question... but then I got to thinking they don't call the method, they get the instance and call he method.. So maybe I'd have to do something like
public interface ICanReadWindows
{
IntPtr MainWindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled);
}
and pass that in to AddClipboardFormatListener
??? I'm not super familiar with how that all plays together so I was hoping to pick peoples brains (such as Hans)
Thank you