By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,723 Members | 975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,723 IT Pros & Developers. It's quick & easy.

DLL and Message Posting

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.

"Ken Williams" <g3***@gb7abc.net> wrote in message
news:bi**********@newsg4.svr.pol.co.uk...
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

Nov 15 '05 #2

P: n/a
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.

"Ken Williams" <g3***@gb7abc.net> wrote in message
news:bi**********@newsg2.svr.pol.co.uk...
So How do I pass a delegate to the DLL do I use something like "ref delegate name" in the call to the DLL ?

Ken

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uy**************@TK2MSFTNGP11.phx.gbl...
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.

"Ken Williams" <g3***@gb7abc.net> wrote in message
news:bi**********@newsg4.svr.pol.co.uk...
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



Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.