Hi,
Is there a way through which i can use an .exe generated using VB code in VC++ or else in the worst case, can i reuse the code which is written in VB in my VC++ application. I am working on visual studio 2008.
Thanks & Regards,
P.Karthik
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Sep 15, 2011, 8:43 AM
You could also add a reference to a VB.NET class library file and then use it from a managed VC++ project.
Karthik AgarwalPosted Sep 16, 2011, 5:41 AM
VulpesPosted Sep 16, 2011, 5:18 AM
However, you can also add a reference as Sam described by selecting Properties from the dropdown and then expanding Common Properties. The dialog that appears is exactly the same as before.
Incidentally, when adding a reference to a VB.NET class library. don't forget to add references to any other assemblies which the former references but haven't been added to your C++/CLI project by default.
If you're not sure you can always open the library first with ildasm.exe to see what's referenced in the manifest but a commonly referenced assembly is Microsoft.VisualBasic.dll which contains all the old VB6-compatible functions as well as the newer 'My' namespace stuff.
Sam HobbsPosted Sep 15, 2011, 11:08 PM
If I understand what you need to do, then this should work. Right-click on the project and choose Properties. Then at the top of the tree view on the left is "Common Properties"; expand that and you will see "Framework and References". Voila! You can now add references as easily as in C# and VB projects.
This technique was not easy for me to find. I did find something explaining how to generate a type library or something like that, and I had problems doing that. So I posted a question in some other forum and the person (a very experienced and knowledgeable expert) was not able to solve the problem I had except he provided me with this easier solution. I soon discovered what was missing from the other way of doing things but now I don't need to do it.
VulpesPosted Sep 15, 2011, 10:58 AM
First create the following VB.Net class library file and build it to classlibrary1.dll:
// classlibrary1.vb
Next create a new C++/CLI console project, usevb.cpp, using the code below:
Now, right click on the project in Solution Explorer and select References from the drop down.
Click on Add New Reference and browse to where classlibrary1.dll is located.
Finally, build and run the project and (hopefully) you should see 5 appear in the console window.
Karthik AgarwalPosted Sep 15, 2011, 9:01 AM
This way will be of more useful than the former.