Calling back from C++ DLL into C# EXE

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
Back
Top