# Tuesday, July 01, 2008

If you have some native code that you have sweated long and hard to create, and now you want to make a shiny new user interface using managed code (WPF probably) or expose the engine to web services (WCF probably) or the like, I hope you know how to do that. Most of the interop discussion out there is focused on that direction. But what if you have a native application and you want to use some cool capabilities from the .NET Framework? Most people really only know how to do it through COM. Your native code can pretend the .NET object is a COM component. But there are other options.

I've referred before to reverse P/Invoke - this is when a .NET delegate is made into a native callback function and handed to native code. It works, but in a way it's still managed-calling-native since the managed code has to start things off by making the delegate and handing it over.

There is a third way. It's a little complicated, but I bet it's faster performing than COM interop, and parts of it could be automated. Essentially, you wrap a C++/CLI managed class around some C# or VB managed class, and then you wrap a native class around that using gcroot<>. It's all explained with diagrams and samples by Sasha Goldshtein. Take a look!

Kate

Tuesday, July 01, 2008 11:24:58 AM (Eastern Daylight Time, UTC-04:00)  #