A question that always pops up is "Can I call managed code from my native process?" And the answer was always "no". Sure, you could create a window and pass window messages between a native process and a managed process, but that's a pretty limited solution, and not a rich programming model. So I wrote a tool to let you do it. It's called Mirror and the source and binaries are available on http://windowsmobile.members.winisp.net/Interop.zip.
Here's how it works. You write a managed assembly that you want to be callable from native code. You'll have to restrict yourself somewhat when it comes to what language features you can use, because Mirror doesn't support everything. But it won't feel too constricting: you can use constructors, methods, properties and indexers. And as for what types you can pass around, you can use all the primitive types (ints, bools, etc.), along with strings and enums. You can even pass around instances of your own classes, as long as the classes themselves are Mirror-compatible.
Then run Mirror's NativeCodeGenerate.exe over your managed assembly, and it will generate C++ code for a class whose interface mirrors that of the managed class. Your app can call that C++ class and it will take care of calling into the managed class. More details are in the readme, but that's pretty much it.
(If you want to know how it works under the covers, I'm using message queues, which are a mechanism CE provides for cross-process communication. They're basically pipes. Mirror contains a reusable managed class for dealing with message queues, so if all you need is raw cross-process communication in your own app, you can steal that class.)
- Jason Fuller