|
-
Sep 12th, 2000, 05:57 PM
#1
Thread Starter
Lively Member
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
-
Sep 13th, 2000, 09:25 AM
#2
Addicted Member
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. 
-
Sep 13th, 2000, 12:34 PM
#3
Monday Morning Lunatic
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
-
Sep 13th, 2000, 03:45 PM
#4
When using API's, it should be ByVal n As Integer)
-
Sep 14th, 2000, 08:14 AM
#5
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|