Invocating DLL compiled with VisualC++ (VStudio98)
Invocating DLL compiled with VisualC++ (VStudio98)
(OP)
Hi, people.
I want to run a function defined into a DLL from VB.
P.E., a simple stupyd example...
long sum (int s1, int s2);
-----
------ DLLmain developed by the C++'s DLL wizard itself
-----
long sum (int s1, int s2)
{
return (s1 + s2)
}
OK, I compile this and correctly declare in VB Module:
Declare Function sum Lib MyDLL (ByVal s1 as Integer, ByVal
s2 as Integer) As Long
but an error was found during the invocation in VB:
res = sum ( 1 + 1 )
something about this: the entry of the DLL couldn't be found
What this?!
THANX
I want to run a function defined into a DLL from VB.
P.E., a simple stupyd example...
long sum (int s1, int s2);
-----
------ DLLmain developed by the C++'s DLL wizard itself
-----
long sum (int s1, int s2)
{
return (s1 + s2)
}
OK, I compile this and correctly declare in VB Module:
Declare Function sum Lib MyDLL (ByVal s1 as Integer, ByVal
s2 as Integer) As Long
but an error was found during the invocation in VB:
res = sum ( 1 + 1 )
something about this: the entry of the DLL couldn't be found
What this?!
THANX
RE: Invocating DLL compiled with VisualC++ (VStudio98)
OK a couple of questions:
1) Your sum isn't going inside the DLLMain, is it? The DLLMain function is called by the OS when the DLL is first loaded. You can't/shouldn't call it yourself.
2) Did you preface your sum() function with "APIENTRY", so that it would be visible to outside callers? It should look like:
int APIENTRY sum(int s1, int s2) {
return (s1 + s2);
}
You can check this my doing a quickview on the DLL (right click on file, choose "QuickView"). Look in the exports section for your function name. If the name is there, but it's mangled, then you need to export it as a "C" function, not a C++ function. Easiest way to do that is rename your source file from .cpp to .c and recompile and link.
Chip H.
PS. Don't forget to include exception handling in your DLL to handle overflow conditions, like when someone calls your function with 2,000,000 and 2,000,000, which would overflow the capacity of an int return.