0

I want to use VB.NET code in win32 (C++) (I dont want to convert my code). I have heard about wrapping VB code in COM but i don't know how to do it. Also, I am not aware if there is an alternative (or any better) way of porting the code.

Any help is appereciated.

Update: I created a class library in vb and saved it as a dll after setting the comvisible attribute to true, then imported it in my c++ project and accessed the interfaces via COM

*thank you everone for helping me out !!!!!!! *

Apoorv
  • 373
  • 1
  • 5
  • 15

2 Answers2

1

You cannot call .NET code directly from a native C++ application, so there is some work involved.

Of course, your question leaves us guessing at why you're wanting to do this, but unless you are still going to be using the library from a .NET application, I would be a strong advocate in favor of porting it (like your title suggests) to C++.

But if you don't want to do this, you have a couple of other options:

  1. Write a wrapper around the VB.NET code using C++/CLI. This would probably be the simpler solution, especially if you're reasonably familiar with both the VB.NET and C++ languages.

  2. Expose the VB.NET methods you need as COM functions, using the <ComVisible(true)> attribute. This is going to be a bit trickier to get going, especially if you're uncomfortable or unfamiliar with COM programming in C++. It's too much to explain in a Stack Overflow answer; investigate purchasing a good book on COM programming. And although you're using VB.NET, the steps are basically the same for C#, for which you'll have much better luck finding examples.

Community
  • 1
  • 1
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
-1

You can't directly port VB into C++, but if you are looking to just switch to a more powerful language and still use the GUI libraries, you can check out C#. It uses very similar code, and a quick google search provided me this program: C# converter. If you really need C++, you could probably then convert the C# code to C++, but there really wouldn't be a need to since C# is VERY close to C++. Just googling that I found this: C++ converter.

I hope this will help you.

phyrrus9
  • 1,441
  • 11
  • 26