Discussion:
Calling managed DLL from unmanaged C++
(too old to reply)
Kenneth Porter
2010-03-05 00:36:44 UTC
Permalink
A vendor has supplied me with a DLL and .LIB of a C++ .NET wrapper around
their C API. No header file. My existing app is all unmanaged C++ with no
special MS libraries (like ATL and MFC). How do I hook this into my
existing solution?

With an unmanaged library I'd just #include the header and add the library
to the link inputs. What's the equivalent for a .NET library?

All the examples I'm finding go the other way, for calling an unmanaged DLL
from a managed language. I already know how to do that. (I needed a wrapper
for a customer using C#.)
MarkusSchaber
2010-03-05 07:53:21 UTC
Permalink
Hi,
Post by Kenneth Porter
A vendor has supplied me with a DLL and .LIB of a C++ .NET wrapper around
their C API. No header file. My existing app is all unmanaged C++ with no
special MS libraries (like ATL and MFC). How do I hook this into my
existing solution?
With an unmanaged library I'd just #include the header and add the library
to the link inputs. What's the equivalent for a .NET library?
All the examples I'm finding go the other way, for calling an unmanaged DLL
from a managed language. I already know how to do that. (I needed a wrapper
for a customer using C#.)
I see at least two possibilities:

- Try to register the .NET wrapper DLL as a COM server, and then call
into the DLL via COM. (This has the advantages of being less work, and
even allows you to bridge over 32/64 Bit boundary by using out-of
process hosting in case your code and the native C++ code is for
different architectures.).

- http://msdn.microsoft.com/en-us/library/9x0wh2z3%28VS.71%29.aspx
describes how you can host the CLR runtime, load the DLL into it, and
then call into it.

Markus

Loading...