Mixing VB and VC++ in solution

  • Thread starter Thread starter DickG
  • Start date Start date
D

DickG

i have some experience using VC++ and Visual Basic (VB) but would like to use
some VB classes in VC++ (legacy) code that is updated to VS2005. I've tried
to figure out how to use VB dlls (class libraries) in VC++ but have given up.

Can someone show me with "Hello World" type of simplicity how to get a
VS2005 VB class to be incorporated and useable in a VC++ project? Please -
no cryptic answers - a very simple sample VS2005 project code would be
wonderful.

DickG
 
DickG said:
i have some experience using VC++ and Visual Basic (VB) but would like to use
some VB classes in VC++ (legacy) code that is updated to VS2005. I've tried
to figure out how to use VB dlls (class libraries) in VC++ but have given up.

Can someone show me with "Hello World" type of simplicity how to get a
VS2005 VB class to be incorporated and useable in a VC++ project? Please -
no cryptic answers - a very simple sample VS2005 project code would be
wonderful.

You can't really, since the IDE was not designed with this in mind. Use one solution with two projects, one for VC++ and one for
VB.NET. That what a "solution" is for.
 
Brian Muth said:
You can't really, since the IDE was not designed with this in mind. Use one solution with two projects, one for VC++ and one for
VB.NET. That what a "solution" is for.
Thanks Brian.

Bear with me, I have not had the need to do this before and I'm not a SW
"professional."

So - if I find it easy to do something in VB, but want to make use of this
function/class/routine or whatever, in VC++, is my only option to create a VB
dll? Or if it is the other way around, I want to use a VC++ capability in my
VB code, a VC++ dll?

If so - can you point me to any simple, basic examples going both ways?
There seems to be a lot of steps before I can get the dll code recognized and
I haven't been able to decipher this yet. I need a "Hello World" example for
both directions, or at least VB dll into VC++.

Thanks -

DickG
 
There is no problem writing a managed class library in C++ and calling the code from VB.NET and vice versa. Whether a class library
is written in VB.NET or managed C++ is irrelevant. It can be called from any other .NET language, including VB.NET.
 
I understand and believe exactly what you say - once a dll is created, the
nuances of the language used to create the dll have been eliminated and the
code is in virtual machine language or some such.

But my problem, as a non-expert, is how to have the VC++ code use the new
dll or VB code to use the dll. What steps must be taken so my VC++ code, for
example, can actually use it. I have created a "Class LIbrary" in VB, which
resulted in a dll file. I then opened up a a VC++ project and did what I
thought was necessary - created a "reference" to the dll. But when I tried
to create and use an object of a type of class I knew was in the dll - I was
not successful.

If I were ignorant of the details of the contents of the dll (suppose I had
not created it myself), how would I know what functions, properties, methods,
classes, etc. are in the dll? Just having the dll file doesn't tell me that.
At least a text file describing the dll might be necessary - but it doesn't
seem that is the process. It seems that something to do with "Imports" and
"Exports" gets involved which I do not understand yet. That is why a very
simple "Hello World" example of the complete process and sequence of project
settings would be ideal.

I don't want to belabor this post. I probably need to spend more time
looking for other dll discussions until I figure this out.

Thanks -

DickG
 
DickG said:
I understand and believe exactly what you say - once a dll is
created, the nuances of the language used to create the dll have been
eliminated and the code is in virtual machine language or some such.

But my problem, as a non-expert, is how to have the VC++ code use the
new dll or VB code to use the dll. What steps must be taken so my
VC++ code, for example, can actually use it. I have created a "Class
LIbrary" in VB, which resulted in a dll file. I then opened up a a
VC++ project and did what I thought was necessary - created a
"reference" to the dll. But when I tried to create and use an object
of a type of class I knew was in the dll - I was not successful.

If I were ignorant of the details of the contents of the dll (suppose
I had not created it myself), how would I know what functions,
properties, methods, classes, etc. are in the dll? Just having the
dll file doesn't tell me that. At least a text file describing the
dll might be necessary - but it doesn't seem that is the process. It
seems that something to do with "Imports" and "Exports" gets involved
which I do not understand yet. That is why a very simple "Hello
World" example of the complete process and sequence of project
settings would be ideal.

I don't want to belabor this post. I probably need to spend more time
looking for other dll discussions until I figure this out.

Thanks -

DickG

If you create a COM dll in VB or VB.Net you can use #import directive in VC++ in
order to use the VB (COM) classes.

http://msdn.microsoft.com/en-us/library/8etzzkb6.aspx

Just remember to call CoInitialize/CoInitializeEx before using the imported COM
Classes.

If you go in the other direction you can use ATL library in VC++ to create a COM
library for VB clients (VB6 or .Net) or use C++ CLI in case of using VB.Net


Regards

PS: If you are familiar with VB6 and ADO (a COM library), you can see an example
of using ADO in VC++ with #import directive
http://support.microsoft.com/kb/169496
 
Thanks for your reply.

I will have to try to follow your suggestions - it may be a bit before I
will get to it. For now - I need to fix a roof leak!

DickG
 
DickG said:
I understand and believe exactly what you say - once a dll is
created, the nuances of the language used to create the dll have been
eliminated and the code is in virtual machine language or some such.

But my problem, as a non-expert, is how to have the VC++ code use the
new dll or VB code to use the dll. What steps must be taken so my
VC++ code, for example, can actually use it. I have created a "Class
LIbrary" in VB, which resulted in a dll file. I then opened up a a
VC++ project and did what I thought was necessary - created a
"reference" to the dll. But when I tried to create and use an object
of a type of class I knew was in the dll - I was not successful.

That is all that is needed. Some things to check:

Did you make the class public?
Did you use the class by its full name including namespace, or else provide
a "using namespace" directive to let the compiler find it?
If I were ignorant of the details of the contents of the dll (suppose
I had not created it myself), how would I know what functions,
properties, methods, classes, etc. are in the dll? Just having the
dll file doesn't tell me that. At least a text file describing the

..NET assemblies contain metadata. Visual Studio has a built-in Object
Browser capability, but you really should download .NET Reflector which is
much more powerful.
http://www.red-gate.com/products/reflector/
dll might be necessary - but it doesn't seem that is the process. It
seems that something to do with "Imports" and "Exports" gets involved
which I do not understand yet. That is why a very simple "Hello
World" example of the complete process and sequence of project
settings would be ideal.

imports and exports aren't used by pure managed code
 
Back
Top