Results 1 to 4 of 4

Thread: Importing DLL classes to VB

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    8

    Smile Importing DLL classes to VB

    Hi, I hope someone knows how to do this because I can't seem to figure it out. I've written a DLL in C++ which contains a class I want to use in VB. Importing functions from a DLL is easy.. but I can't figure out how to import a class.

    I am exporting my class from my DLL as such:

    class __declspec(dllexport) TestClass {
    public:
    int x;
    };

    Notice the "__declspec(dllexport)" flag so i am NOT working with any DEF files or anything like that. How may I instantiate a TestClass object in my VB app?

    Thanks in advance.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    When it comes to classes VB can only handle classes in COM objects.
    What you have to do is set a reference to the dll and instanciate an object in the normal way.
    VB Code:
    1. Private obj As ClassName
    2. Private Sub Form_Load()
    3.     Set obj = New ClassName
    4. End Sub
    Best regards

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    8
    thanks. ok.. so i should reference it in my com object and instantiate the class in my vb prog like you've shown me. Got it, but how can i reference the class in my C++ DLL from my COM object? Do you know what the line of code would look like?

    Thank you very much for your kind help.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Sorry I wasn't very clear. VB can only use classes if the classes themself has a COM interface.
    You can't use export classes in VB.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width