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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Sep 15, 2011, 4:43 AM EDT
You could also add a reference to a VB.NET class library file and then use it from a managed VC++ project.
Karthik AgarwalRank #2,270 · 620 reputationPosted Sep 15, 2011, 5:01 AM EDT
This way will be of more useful than the former.
VulpesRank #55 · 29.2K reputationPosted Sep 15, 2011, 6:58 AM EDT
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.
Sam HobbsRank #107 · 20.5K reputationPosted Sep 15, 2011, 7:08 PM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Sep 16, 2011, 1:18 AM EDT
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.
Karthik AgarwalRank #2,270 · 620 reputationPosted Sep 16, 2011, 1:41 AM EDT