Calling back from C++ DLL into C# EXE

G

Guest

I have an MMI application written in C# for Windows Mobile 5.0 (PPC). I have
a business logic DLL, however, written in unmanaged C++ to which my MMI has
to interface with. I am able to call into this DLL using the standard
practise as illustrated below:

using System.Runtime.InteropServices;
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);

I also have a requirement wherein my DLL has to call into/send event to
(along with a data structure) to the managed module.

1. How can i achieve this? An illustration or example would be highly
appreciated.

2. (dumb question) If i do a DllImport as above, does the dll get loaded
into the main C# process address space? or can i keep doing DllImport at will
in multiple classes existing in the same address space?

Regards,
Sanjay.
 
P

Paul G. Tobey [eMVP]

1. The ways are too numerous to count. What data has to be transferred from
C++ to C#? If none, you just need an event. You could send a message to
the main form window and catch that using the OpenNETCF IMessageFilter
scheme (check the site, www.opennetcf.org for any examples), or just set an
operating system event (SetEvent() in C++), and either periodically check
that event in C# or actually wait on it (WaitForSingleObject). If you have
to send data, the size and lifetime of the data will affect how you do this.

2. The DLLImport just provides a means to call the function. There's no
address space effect of the import itself.

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top