none
Use c++ class in VB.net

    Question

  • I have made a compiled a c++ class to a dll in VS 2017.

    The header file myClass.h:

    pragma once

    class myCLass

    {

    public:

                    char Item[17];

                    char Name[37];

                    short Group;

                    double Price;

                    myClass(char *Input );

                    ~myClass();

    };

    I want now to create an instance of this class in a VB-winfoem project (VS 2017 Community) in the same solution.  In the VB winform program.  I want to input a string. The constructor of the class use the string, and I want to show the values in my VB form.

    Is it possible or must I change the c++ project and dll?

    Thursday, April 6, 2017 2:51 PM

All replies

  • AFAIK, C++ creates unmanaged code libraries so you would either need to create a COM interface for your Class and generate a COM DLL or export functions and create a standard Windows DLL. Since you are creating a Class then the COM method would be more appropriate.

    I'm not sure why you are using C++, but you may want to consider using C# or VB.NET to create a managed Class Library (.NET DLL) instead.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, April 6, 2017 4:34 PM
  • OK, so it looks like you may be able to create a managed Class Library from C++ as well:

    http://www.aravind.ca/Tutorials?managedcpp


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, April 6, 2017 4:42 PM
  • Hi hjl1,

    I suggest you to use P\Invoke in VB.net, More detailed info, please refer to how to use P\Invoke in VB.net.

    Besides, there are a number of other solutions, such as COM, other IPC techniques.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 7, 2017 2:21 AM
    Moderator
  • Thanks for your suggestion. 

    Can managed C++ classes use a third-party library's?

    How do I make managed C++ in VS-2017 Community?

    Friday, April 7, 2017 7:07 AM
  • I am using C++ because I need to use a third-party library (.lib file) meant for C or C++. I have managed to make a console application in Microsoft C++ to work with the library, but not VB.net directly (or C#). 

    Do you have any suggestion (or examples) on how I make the COM DLL or the export functions?  I don't necessary need the class, but maybe a function returning a structure.  I have looked at a lot of dllimport examples, but I cannot see any with a constructor needing a parameter (string) and returning a structure.  Either a function without parameters returning a structure (like systemtime) or a function returning a number with two number input (like adding numbers). 

    Friday, April 7, 2017 7:34 AM
  • Hi Hjl1,

    >>How do I make managed C++ in VS-2017 Community?

    Open Visual Studio 2017--New project---Visual C++---CLR, then you can get managed C++.

    >>how I make the COM DLL or the export functions? 

    Open Visual Studio 2017---New Project---Visual C++---ATL, then you can get COM DLL.

    More detailed info about export functions, please refer to this link.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 7, 2017 8:03 AM
    Moderator
  • Thanks for your suggestion. 

    Can managed C++ classes use a third-party library's?

    How do I make managed C++ in VS-2017 Community?

    Yes if that are also managed library's

    However, you focus you to much on C++, that is just a program language.

    The difference is that it can be used for two kinds of technologies (Com and .Net). 

    First decide on what technology you want to focus. 

    If it is both then look at the replies from Cherry but be aware, in the way you ask this, you miss probably a lot of knowledge so it will be like going currently to Raqqa with the Rusian flag on your bag.  


    Success
    Cor


    Friday, April 7, 2017 10:33 AM
  • Thanks for your suggestion. 

    Can managed C++ classes use a third-party library's?

    How do I make managed C++ in VS-2017 Community?

    I don't see any reason why you couldn't use a third-party library in a C++ project. I would ask C++ specific development questions in the Visual C++ forum:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vcgeneral


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, April 7, 2017 12:03 PM