Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invocating DLL compiled with VisualC++ (VStudio98) 1

Status
Not open for further replies.

arlequin

Programmer
Sep 21, 1999
232
UY
Hi, people.<br>
I want to run a function defined into a DLL from VB.<br>
P.E., a simple stupyd example...<br>
<br>
long sum (int s1, int s2);<br>
<br>
-----<br>
------ DLLmain developed by the C++'s DLL wizard itself<br>
-----<br>
long sum (int s1, int s2)<br>
{<br>
return (s1 + s2)<br>
}<br>
<br>
OK, I compile this and correctly declare in VB Module:<br>
<br>
Declare Function sum Lib MyDLL (ByVal s1 as Integer, ByVal <br>
s2 as Integer) As Long<br>
<br>
but an error was found during the invocation in VB:<br>
<br>
res = sum ( 1 + 1 )<br>
<br>
something about this: the entry of the DLL couldn't be found<br>
<br>
What this?!<br>
THANX
 
Hi arlequin!<br>
<br>
OK a couple of questions:<br>
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.<br>
<br>
2) Did you preface your sum() function with &quot;APIENTRY&quot;, so that it would be visible to outside callers? It should look like:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;int APIENTRY sum(int s1, int s2) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (s1 + s2);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
You can check this my doing a quickview on the DLL (right click on file, choose &quot;QuickView&quot;). 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 &quot;C&quot; function, not a C++ function. Easiest way to do that is rename your source file from .cpp to .c and recompile and link.<br>
<br>
Chip H.<br>
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.<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top