Results 1 to 5 of 5

Thread: exporting functions.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95
    i've read a lot about exporting C++ functions to VB but never had any luck. I keep getting some stupid error like "cannot find DLL entry point". I don';t know what I'm doing wrong.

    this is my C++ code
    Code:
    int __stdcall ThisFunction( int n ){
        return n;
    }
    this is my VB code.
    Code:
    Private Declare Function ThisFunction Lib "ThisLib" (ByVal n As Integer) As Long
    
    Private Command1_Click()
        Print ThisFunction(42)
    End Sub

  2. #2
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161
    you have to write a global function like this:
    Code:
    extern "C" __declspec(dllexport) int __stdcall
    MyFunction(int n)
    {
      //do something
    }
    and save it as dll
    the important thing is "dllexport". It's required if you want to export the function (use it with other modules).

    you can call the function from VB now this way:
    Code:
    Declare Function MyFunction Lib "C:\Dllpath\DllName.dll" (n as Integer) as Integer
    it's posssible that you have to use an Alias name for the function, you can look it up with Dependency Walker. If you're not sure, just try it without the alias name first. If you get an error telling you the entry point wan't found in the dll, look for the Alias Name.
    extern "C" should prevent C++ from using other names, but it doesn't work sometimes anyway... that's why you maybe will need an alias.


    [Edited by Razzle on 09-13-2000 at 10:33 AM]
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I've noticed you don't always need to use extern "C" for DLLs. Also, you missed a vital step. You need to provide a .DEF file (I think) which specifies the functions:
    Code:
    LIBRARY "DLLName"
    
    EXPORTS
        MyFunction
    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

  4. #4
    Guest
    When using API's, it should be ByVal n As Integer)

  5. #5
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161
    oops
    sorry, I forgot that
    I beg your pardon
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

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