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

Posted on 2007-10-21
Last Modified: 2008-09-12
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!
Question by:riceman0
    1 Comment
    LVL 19

    Accepted 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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now