Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

0 views
Skip to first unread message

Greco@discussions.microsoft.com Lee Greco

unread,
Oct 28, 2004, 11:05:08 AM10/28/04
to
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?

Bonj

unread,
Oct 31, 2004, 11:31:08 AM10/31/04
to
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#.

"Lee Greco" <Lee Gr...@discussions.microsoft.com> wrote in message
news:986AA0E8-9586-4447...@microsoft.com...

0 new messages