-
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
-
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]
-
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
-
When using API's, it should be ByVal n As Integer)
-
oops
sorry, I forgot that :(
I beg your pardon