Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2006

Tip: Looking for answers? Try searching our database.

Consuming VB.NET DLL in VC++.NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simon Smith - 23 Nov 2006 09:27 GMT
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
William DePalo [MVP VC++] - 23 Nov 2006 14:31 GMT
> 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
[quoted text clipped - 3 lines]
> 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/microsoft.public.dotnet.languages.vc/browse_frm/t
hread/6bfd1115e804cc58/4f1afe6d2e0f0113?lnk=st&q=&rnum=2&hl=en#4f1afe6d2e0f0113


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

Regards,
Will
Simon Smith - 23 Nov 2006 16:26 GMT
> > 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
[quoted text clipped - 17 lines]
> 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
Simon Smith - 23 Nov 2006 16:54 GMT
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
William DePalo [MVP VC++] - 24 Nov 2006 05:33 GMT
> 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
Simon Smith - 24 Nov 2006 10:24 GMT
> > I was under the impression that the app was targeting .net, but it's a
> > third
[quoted text clipped - 12 lines]
> 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.
Ben Voigt - 24 Nov 2006 15:30 GMT
> Hi,
>
[quoted text clipped - 21 lines]
> 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.

> Any help is gratefully received!
>
> Thanks
>
> Simon

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.