views:

185

answers:

2
+1  Q: 

Create Native DLL

I'm C# programmer, and don't introduce with Native. I have a Native DLL, & I'v to use that in my project, but cause some of types are impracticable in Managed code. I'll to prepare a DLL in Native(C++), and I want when an event occure, then aware my Managed Code; How can I do that?

+1  A: 

If you want to handle Native events in your C# code, then I think your best bet is to write a C++/CLI DLL which would work as the intermediate layer between C++ Native DLL and C# DLL. That way you can handle events in the intermediate library and pass them on to be captured again by the Managed DLL.

Another option is to write your Native DLL as a COM DLL and raise COM Dispatch Events from there. By creating an Interop of this COM DLL, you can capture the Events directly in your C# DLL. But this route has a very steep learning curve if you are new to COM Programming.

Aamir
+1  A: 

If your native DLL's API lets you register a function pointer as a call-back to be invoked when the event is raised, you can marshal a normal C# delegate as a function pointer (Marshal.GetFunctionPointerForDelegate) and just register the managed delegate via P/Invoke.

Steve Gilham