sending pointers of C#.NET methods to native dll

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hi,

I need to send the pointer of a C# method to a native user32.dll method. How
can I do that?

To be specific - the method is SetWindowLong of user32.dll which in VB6 is
being is being called as follows -
glOldWindowProc = SetWindowLong(glWindowHandle, GWL_WNDPROC, AddressOf
WndMessage)

My question pertains to the last parameter - "AddressOf WndMessage" -
WndMessage is a method in a class in VB6.

How do I do the same thing in C#.NET?

Will appreciate any pointers.

Thanks

Vani
 
Vani,

In .NET, you can use a delegate, and pass that. It will convert it to a
function pointer which can be called by unmanaged code.

However, if your control is a .NET control, then I would recommend
deriving a class from it, and overriding the WndProc method.

Or, derive a class from NativeWindow (if not a .NET control) and pass
the handle to that, overriding the WndProc method.

Hope this helps.
 
Back
Top