6

Can a native DLL call a .NET DLL?

3 Answers3

4

No, you need to use managed c++

ConsultUtah
  • 6,639
  • 3
  • 32
  • 51
  • 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 Aug 07 '09 at 16:34
1

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.

tranmq
  • 15,168
  • 3
  • 31
  • 27
  • Because I am not familiar with COM and will do everything I can to avoid learning it :) –  Aug 07 '09 at 21:24
  • 1
    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 Sep 05 '09 at 01:46
1

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.

Stéphane Bonniez
  • 4,577
  • 3
  • 21
  • 16