Click to See Complete Forum and Search --> : exporting functions.
Zej
Sep 12th, 2000, 05:57 PM
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
int __stdcall ThisFunction( int n ){
return n;
}
this is my VB code.
Private Declare Function ThisFunction Lib "ThisLib" (ByVal n As Integer) As Long
Private Command1_Click()
Print ThisFunction(42)
End Sub
Razzle
Sep 13th, 2000, 09:25 AM
you have to write a global function like this:
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:
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]
parksie
Sep 13th, 2000, 12:34 PM
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:
LIBRARY "DLLName"
EXPORTS
MyFunction
When using API's, it should be ByVal n As Integer)
Razzle
Sep 14th, 2000, 08:14 AM
oops
sorry, I forgot that :(
I beg your pardon
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.