Using a C# DLL in unmanaged C++ code

  • Thread starter Thread starter Peter Steele
  • Start date Start date
P

Peter Steele

Anyone have a good reference on how to use a DLL written in C# in unmanaged
C++ code?
 
Peter,

About the only way you can do this is to export your types through COM
interop. You will have to set the "register for COM interop" flag on your
project to true, or run the regasm.exe tool.

Once you do that, you can access your .NET components as if they were
any other COM objects.

Hope this helps.
 
Peter Steele said:
Anyone have a good reference on how to use a DLL written in C# in
unmanaged
C++ code?

There are a few ways to do this:
- COM interop
- a managed C++ wrapper DLL
- hosting the CLR

What do you want to do?

Niki
 
I have a C++ DLL that I need to access from a VC++ application. Whatever way
accomplishes this in the easiest fashion is what I want to do...
 
Peter Steele said:
I have a C++ DLL that I need to access from a VC++ application. Whatever
way
accomplishes this in the easiest fashion is what I want to do...

I thought it was a C# DLL?
Anyway: COM interop is quite easy if you are already familiar with COM, and
if performance doesn't matter (too much).
Otherwise, create a managed C++ DLL, which can export ordinary DLL functions
(can be used like any other DLL from your VC++ app); These functions can in
turn call the managed C# code.

Niki
 
Oops--yes, it's a C# DLL. Typo...

Peter

Niki Estner said:
I thought it was a C# DLL?
Anyway: COM interop is quite easy if you are already familiar with COM, and
if performance doesn't matter (too much).
Otherwise, create a managed C++ DLL, which can export ordinary DLL functions
(can be used like any other DLL from your VC++ app); These functions can in
turn call the managed C# code.

Niki
 
Back
Top