Results 1 to 10 of 10

Thread: How to use DLL created in VC++ on VB programs?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Posts
    130
    Goodday everybody...

    I would like to know how do i use DLL developed in VC++ in VB programs? What are the procedure i need to do to link it to my VB programs and how do i actually use the functions available in the DLL on my VB programs?

    Your help will be most appreciated...

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You should have declared the functions in the DLL for export and then you can use them in VB:
    Code:
     
    Private Declare Function FunctionName Lib "dllname.dll" (arguments as something) as something
    'this is if the function in the dll returns a value else use
    
    Private Declare Sub FunctionName Lib "dllname.dll" (arguments as something)
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Posts
    104
    Do you know if you have to specify the path of the dll or not?

    Does windows start looking for it in Windows\System or the application's directory?

    Just curious.
    Um americano que fala portugues.

  4. #4
    New Member
    Join Date
    Oct 2000
    Posts
    2
    Hi ttingen, if you dont specify the path, windows will look for the dll files based on the directories you've specified in the PATH ENVIRONMENT, and they usually check in the current folder first (the folder in which you store your VB project files).
    If you do not put the dll in one of the directories specified in the PATH Environment, you may specify the path so that windows can locate the dll file directly.

    Hope it helps.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Posts
    130
    thanks vlatko...
    export the functions in th DLL? how do i do that?

    hi misterkiasu...
    where do i specify the PATH ENVIRONMENT?

  6. #6
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    If you put this in a C++ dll:
    Code:
    void _stdcall message(HWND hwnd)
    {
    MessageBox(hwnd,"text","Text",MB_OK);
    }
    and this in VB:
    Code:
    Private Declare Sub Message Lib "dllname.dll" (ByVal hwnd as Long)
    
    'call it
    Message Form1.hWnd
    'pops up a message box
    You can also use a def file and write the function names you want to export there

    EXPORTS
    Message
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Posts
    130
    thanks vlatko...

    but this can be used if the DLL is created as a Library-Type DLL, right?
    what if i want to create an ActiveX DLL? can i create an ActiveX DLL in VC++ and how do i do it?

    and also, this can bed use only if the function is a general function, right? what if i want to use a function which is in a class? how should i do it? In VB, how can i declare an object of the class created in the DLL?

    correct me if i'm wrong...


  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    At the moment you can't use a C++ class from VB. All the virtuality semantics break down once you start copying things around .
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Posts
    130
    parksie...

    what do you mean by "All the virtuality semantics break down once you start copying things around"?

    can you please explain? thanks...

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In C++, you have virtual inheritance. This means that a pointer to an object may not actually refer to that TYPE of object. It is usually used to great advantage in COM. What happens:
    Code:
    class Base {
    public:
        int Function() { return 5; }
    };
    
    class Derived: public Base {
        int Function() { return 1; }
    }
    So, Derived is derived from Base. Normal sense indicates:
    Code:
    Base *pBase = new Base;
    Derived *pDerived = new Derived;
    
    pBase->Function(); // Returns 5
    pDerived->Function(); // Returns 1
    If you do THIS, though:
    Code:
    Base *pWhat = new Derived;
    
    pWhat->Function(); // Returns 1
    The magic of virtual inheritance is what causes the derived class' function to be called.

    This is virtuality semantics.

    In VB, you can't use a C++ class because there is no way to tell, even when reading vfptr, what function should be called.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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