Consuming VB.NET DLL in VC++.NET

G

Guest

Hi,

I'm sure this is a question that comes up reasonably regularly, but I'm
getting an error with the forum search function at the moment, and haven't
found anything with a browse, so forgive me if this is repeating things!!

Should also clarify that it's a VERY long time since I've done much C++, so
I may well have forgotten something simple...

I have a VB.NET dll that I'd like to be able to use in a VC++.NET
application (all using VS.NET 2003). all the documentation I've found
suggests that all I need to do is to copy the DLL into an output folder and
tell the compiler to look in that folder to resolve #using directives, then
add a #using "VBFunctions.dll" into my cpp file.

Following that, I should be able to create an instance of this class and
happily use it. I've tried this with:

VBFunctions *oFunctions = new VBFunctions();

But I get a "VBFunctions : undeclared identifier" when trying to build the
solution.

Any help is gratefully received!

Thanks

Simon
 
W

William DePalo [MVP VC++]

Simon Smith said:
I have a VB.NET dll that I'd like to be able to use in a VC++.NET
application (all using VS.NET 2003). all the documentation I've found
suggests that all I need to do is to copy the DLL into an output folder
and
tell the compiler to look in that folder to resolve #using directives,
then
add a #using "VBFunctions.dll" into my cpp file.

Is your VC++ application native or managed - i.e. does it target Win32 or
..Net? A simple procedure such as you sketched should work in the latter
case.

If though, you have a Win32 caller and a .Net callee, there is more work to
do. I sketch a method for doing that here:

http://groups.google.com/group/micr...f0113?lnk=st&q=&rnum=2&hl=en#4f1afe6d2e0f0113

(My sample uses a C# callee but that doesn't matter)

Regards,
Will
 
G

Guest

William DePalo said:
Is your VC++ application native or managed - i.e. does it target Win32 or
..Net? A simple procedure such as you sketched should work in the latter
case.

If though, you have a Win32 caller and a .Net callee, there is more work to
do. I sketch a method for doing that here:

http://groups.google.com/group/micr...f0113?lnk=st&q=&rnum=2&hl=en#4f1afe6d2e0f0113

(My sample uses a C# callee but that doesn't matter)

Regards,
Will
I was under the impression that the app was targeting .net, but it's a third
party project template that I'm not too familiar with. Given that just
importing the DLL hasn't worked, I'll try the interop services method you
have linked to; I'm out of other ideas, so why not!

Thanks for your help.

Si
 
G

Guest

OK. So I've done this and I now get a message "A namespace with this name
does not exist"

I've checked the registry after the regasm bits and pieces, and I've spelt
the namespace right in the cpp.

The only thing I couldn't do from your example was the [ClassInterface] bit;
I can't find any reference to this in VB.net
 
W

William DePalo [MVP VC++]

Simon Smith said:
I was under the impression that the app was targeting .net, but it's a
third
party project template that I'm not too familiar with. Given that just
importing the DLL hasn't worked, I'll try the interop services method you
have linked to; I'm out of other ideas, so why not!

Well, the sample wo which I pointed to is for interoperating between the
Win32 and .Net platforms. If you are targetting .Net in the pieces written
in C++, my sample is beside the point.

If you are not sure what you have you can inspect the switches on the
compiler and linker command lines. If you are compiling with /clr and
linking against mscoree.lib than you are targetting .Net

Regards,
Will
 
G

Guest

William DePalo said:
Well, the sample wo which I pointed to is for interoperating between the
Win32 and .Net platforms. If you are targetting .Net in the pieces written
in C++, my sample is beside the point.

If you are not sure what you have you can inspect the switches on the
compiler and linker command lines. If you are compiling with /clr and
linking against mscoree.lib than you are targetting .Net

Regards,
Will
The C++ parts are targeting Win32, so the sample is valid. I still can't get
it to work, though. I've checked the registry and I'm using the correct class
names and files, but whatever I do I get a "undeclared identifier" error when
I try to reference anything using the class name.
 
B

Ben Voigt

Simon Smith said:
Hi,

I'm sure this is a question that comes up reasonably regularly, but I'm
getting an error with the forum search function at the moment, and haven't
found anything with a browse, so forgive me if this is repeating things!!

Should also clarify that it's a VERY long time since I've done much C++,
so
I may well have forgotten something simple...

I have a VB.NET dll that I'd like to be able to use in a VC++.NET
application (all using VS.NET 2003). all the documentation I've found
suggests that all I need to do is to copy the DLL into an output folder
and
tell the compiler to look in that folder to resolve #using directives,
then
add a #using "VBFunctions.dll" into my cpp file.

Following that, I should be able to create an instance of this class and
happily use it. I've tried this with:

VBFunctions *oFunctions = new VBFunctions();

But I get a "VBFunctions : undeclared identifier" when trying to build the
solution.

You will also need a using namespace statement.

Get .NET Reflector (http://www.aisto.com/roeder/dotnet/) in order to find
out the exact names available inside your VB assembly.
 

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