Trouble adding a reference to C++ DLL in C#

G

Guest

A third party vendor has provided me with a DLL authored in C++ .Net. The
vendor's package includes the DLL, .lib and all necessary .h files and sample
code to develop a C++ .NET app. For the C++ sample project to run, the .lib
file needs to be added to the additional dependencies, the Stack Reserve Size
needs to be 2meg, the WIN32 directive must be included, and the runtime
library must be Multi-threaded Debug DLL. The sample app includes a few
"extern template class DLLIMPORT std::vector<namespace::someclass*>"
statements to access the objects in the external library. I can get the C++
sample app to work just fine.

I am not a C++ developeer and would much rather develop an app using C# or
VB.Net, but when I try to add a reference to the DLL, I receive a "This is
not a valid assembly or COM component" error message.

How can I go about accessing the objects and methods in this external
library in a VB.Net or C# app?
 
B

Bonj

You would need to create a managed wrapper for it.
Something like:
Create a mixed dll that has a class to expose to C#, and that links to the
..lib file and includes the .h file that they provide, like
//thedll.cpp
#include "3rdparty.h" //contains, say, extern void the3rdpartyfunc();
#using <mscorlib.dll>
using namespace System;
public __gc class ThirdParty
{
public:
static void Call3rdPartyFunc()
{
the3rdpartyfunc();
}
};
You should be able to then call this from C#.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top