• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 908
  • Last Modified:

Use C++ class in my VB.NET project?

Hi, I've got some old C++ code I'm having trouble converting to VB.NET.  So instead, I'm trying to add a C++ project to my solution, write it into a C++ class, and then (hopefully) access that C++ class from my VB.NET class.

So I added a C++ DLL project to my solution, added a new class, and I'm not sure how to access these classes from my VB.NET classes.  I added the reference to the other project, and nothing new pops up in intellisense as far as new types or namespaces available.

Is this possible?  If so, does anyone have some quick-start steps?

If not, what forms of communication are possible between C++ DLL and a VB.NET project in the same solution?

Thanks in advance!
1 Solution
To use C/C++ dll's from VB.NET, you have two choices:

1) Write managed C++ which can be used directly by your VB.NET project with a project or assembly reference.  You write the interface needed by VB.NET in managed C++ and you can call ative C++ code directly with the magic of .NET C++.

2) Make sure the functions intended for use by VB.NET are declared with the WINAPI macro or use _stdcall convention and are exported.  You can then use the VB Declare statement to import the functions.

You have evidently not done #1, and it's not likely you did #2 unintentionally, so you need to go back and use one of these two methods.

In general, I think the managed C++ approach is easier, but if you are not familiar with managed C++ the Declare approach may be easier.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now