PC Review


Reply
Thread Tools Rate Thread

Consuming VB.NET DLL in VC++.NET

 
 
=?Utf-8?B?U2ltb24gU21pdGg=?=
Guest
Posts: n/a
 
      23rd Nov 2006

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
 
Reply With Quote
 
 
 
 
William DePalo [MVP VC++]
Guest
Posts: n/a
 
      23rd Nov 2006
"Simon Smith" <(E-Mail Removed)> wrote in message
news:A5335019-9D3C-419F-B1C0-(E-Mail Removed)...
> 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/micro...1afe6d2e0f0113

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

Regards,
Will


 
Reply With Quote
 
=?Utf-8?B?U2ltb24gU21pdGg=?=
Guest
Posts: n/a
 
      23rd Nov 2006


"William DePalo [MVP VC++]" wrote:

> "Simon Smith" <(E-Mail Removed)> wrote in message
> news:A5335019-9D3C-419F-B1C0-(E-Mail Removed)...
> > 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/micro...1afe6d2e0f0113
>
> (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
>

 
Reply With Quote
 
=?Utf-8?B?U2ltb24gU21pdGg=?=
Guest
Posts: n/a
 
      23rd Nov 2006
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
 
Reply With Quote
 
William DePalo [MVP VC++]
Guest
Posts: n/a
 
      24th Nov 2006
"Simon Smith" <(E-Mail Removed)> wrote in message
news:B30DFB0A-E2B0-4569-95CF-(E-Mail Removed)...
> 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


 
Reply With Quote
 
=?Utf-8?B?U2ltb24gU21pdGg=?=
Guest
Posts: n/a
 
      24th Nov 2006


"William DePalo [MVP VC++]" wrote:

> "Simon Smith" <(E-Mail Removed)> wrote in message
> news:B30DFB0A-E2B0-4569-95CF-(E-Mail Removed)...
> > 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
>
>
>

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.
 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      24th Nov 2006

"Simon Smith" <(E-Mail Removed)> wrote in message
news:A5335019-9D3C-419F-B1C0-(E-Mail Removed)...
>
> 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.

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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SVChost.exe is consuming 99% CPU =?Utf-8?B?Um9uYWsgUGF0ZWw=?= Windows XP Help 2 20th Jun 2007 01:27 PM
Consuming memory Tom Microsoft Outlook Discussion 2 9th May 2007 04:56 PM
Winlogon.exe consuming CPU Franky Windows XP General 3 7th Aug 2006 06:13 PM
ie6 consuming handles Dave Anderson Windows XP Internet Explorer 1 26th Nov 2005 05:33 PM
consuming RAM ... Fabio Gianzanti Windows XP Embedded 4 9th Feb 2004 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 PM.