VolleyMan
asked on
Call C DLL from VB6
I have seen variations on this question asked before, but I have tried those suggestions and nothing seems to work correctly for me. I have a simple C DLL in which I have added the following routine (built in VC++ 6):
char __declspec(dllexport) _stdcall Silly_VB
(char number)
{
return (5);
}
In my VB6 code:
Private Declare Function Silly_VB _
Lib "MyDLL.dll" _
(ByVal a As Byte) As Byte
Dim bytA As Boolean
bytA = Silly_VB(1)
When I run the VB app I get a runtime 453 saying that DLL entry by that name could not be found. I used Dependency Walker and it shows an entry _Silly_VB@4 so that is why I can't see it in my VB app. Anybody have any suggestions?
thanks
char __declspec(dllexport) _stdcall Silly_VB
(char number)
{
return (5);
}
In my VB6 code:
Private Declare Function Silly_VB _
Lib "MyDLL.dll" _
(ByVal a As Byte) As Byte
Dim bytA As Boolean
bytA = Silly_VB(1)
When I run the VB app I get a runtime 453 saying that DLL entry by that name could not be found. I used Dependency Walker and it shows an entry _Silly_VB@4 so that is why I can't see it in my VB app. Anybody have any suggestions?
thanks
Sorry, That should be
"I believe in VC++ 6 char is 4 bytes."
"I believe in VC++ 6 char is 4 bytes."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You'll have to recompile the C++ project using the "stdcall" compilation (you can find it on the project properties).
This will create a function name that is compatible with the one you need.
HTH
M.
Ofcourse u will get error cause you have declared return Data Type for ur function as char and using as Byte in Declaration in vb Ty using Integer
cause in c we can evaluate C char with integer
cause in c we can evaluate C char with integer
Also if You remove __declspec(dllexpot) it doesn't matters
it will work for VB
only Make sure to declare it in project1.def as
Exports
it will work for VB
only Make sure to declare it in project1.def as
Exports
Also if You remove __declspec(dllexpot) it doesn't matters
it will work for VB
only Make sure to declare it in project1.def as
Exports
it will work for VB
only Make sure to declare it in project1.def as
Exports
Also if You remove __declspec(dllexpot) it doesn't matters
it will work for VB
only Make sure to declare it in project1.def as
Exports
Silly_VB
it will work for VB
only Make sure to declare it in project1.def as
Exports
Silly_VB
replace project1.def wih UR CPP file Name
ASKER
Actually the answer was a little more complicated in that the name was getting mangled, but it needed to be either alias'ed in the DEF file OR in the VB source.
Here is the url to the correct answer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_calling_dll_functions_from_visual_basic_applications.asp
thanks everyone.
Here is the url to the correct answer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_calling_dll_functions_from_visual_basic_applications.asp
thanks everyone.
Private Declare Function Silly_VB Lib "MyDLL.dll" _
(ByVal a As Long) as Long
If I am wrong on this sombody please correct me! :)
Hope this helps