I am trying to create an instance of a legacy c++ class in VB.NET. I have followed the instructions on the following webpage: http://windowsdevcenter.com/pub/a/dotnet/2004/03/29/mcpp_part3.html?page=2
1) Created a Visual C++ project with one file (MFoo.cpp) and the following code:
class Foo
{ public:
// constructor
Foo(void) {}
// destructor
~Foo(void) {}
// some method
void DoSomeFoo(){} };
__gc class MFoo
{ public: Foo * _foo;
public:
// constructor
MFoo() { _foo = new Foo();}
// destructor
~MFoo() { delete _foo; }
// method
void ManagedDoSomeFoo() { _foo->DoSomeFoo(); } };
2) Built the project in Visual C++ producing a DLL 3) Created a reference to the DLL (created in part 2) in a VB.NET application
I now get an error when I try to create an instance of the C++ object i.e. Dim foo As New MFoo. The error is: MFoo is not available in this context because it is Friend.
You need to declare the the class MFoo as public, replace the line __gc class MFoo
with public __gc class MFoo