DLL and Message Posting

  • Thread starter Thread starter Ken Williams
  • Start date Start date
K

Ken Williams

Hi I have a DLL written in C/C++ that is passed Hwnd when it is called.

When the DLL has data for the calling program it uses Hwnd to post a windows
message back to the calling program saying it wants attention.

I have looked at Delegates and events, but it's not obvious how I can
replicate this feature in C#.

Anyone got a sample of code that does something similar in C# ?

Thanks Ken
 
You can still use Handles (Windows Forms equivalent of an Hwnd) and message
posting calls to send data back and forth. If you really want to do it the
..NET way then delegates will work. You simply have the *dll* accept a
delegate as a parameter, and have the caller pass in a handler that matches
the delegate. Then you can simply call that method inside of your dll and
the caller will get the information. It isn't nearly the same as the
Windows Message Pump, but all of that still exists if you are familiar with
it and still want to use it.
 
Delegates aren't really meant to be marshalled to an external dll unless the
external dll is a mixed mode C++ assembly or an actual piece of managed
code. I am sure there is a way to do the marshalling so that it looks like
nothing more than a function pointer, but I think it is also possible for
the location of the function pointer to change and you wouldn't want to call
back onto a garbage pointer. If you are still wanting an unmanaged dll I
would simply stick with passing the Handle around and using your message
pump code.
 
Back
Top