tags:

views:

200

answers:

3

Is it possible to build a .NET assembly callable from a native assembly writing in C# alone without using COM?

+3  A: 

No, you need to use managed c++

consultutah
Or a wrapper written in managed C++.
0xA3
Exactly. What we do is create a thin wrapper with standard extern "C" exports in Managed C++, then write the real code in C#.
consultutah
+1  A: 

Without using COM, you have to write a C++/CLI wrapper. Your native code that includes the header file of your wrapper needs to be compiled with /clr (common language runtime support).

Just for curiosity, why not using COM interop? Check out the regasm.exe and tlbexp.exe tools.

mqbt
Because I am not familiar with COM and will do everything I can to avoid learning it :)
beef
COM also suffers from the nasty DLL hell problem due to global registration. It's possible to do registration-free COM but the documentation is confusing and there are bugs http://stackoverflow.com/questions/617253/is-anyone-successfully-using-registration-free-com-with-net-components
Wim Coenen
+2  A: 

You need something to make the managed world and the unmanaged world work together. If you don't want to use COM, you can create wrapper classes in C++/CLI.

Here is an article that can get you started: .NET to C++ Bridge.

Steph
Thank you for the article. It is helpful.
beef