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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a DLL in C++

Status
Not open for further replies.

BobbyB

Programmer
Feb 19, 2002
44
CA
I've used the folowing code to retrieve a dll function which has this prototype...

__declspec(dllexport) void CreateGauge
(const char*, const char*, int);
-------------------------

here's the export table we can found when we take a look at the dll's quickview...

0000 00001041 ?CreateGauge@@YAXPBD0H@Z
-------------------------

#include <windows.h>
void main(){
HINSTANCE hLib;
void (*MyFunc)(const char*, const char*, int);

hLib = LoadLibrary(&quot;YtriaGUI.dll&quot;);
if (hLib){
MyFunc = (void (__cdecl *)(const char*, const char*, int))GetProcAddress(hLib, );

if (MyFunc!=NULL){
MyFunc(&quot;test1&quot;, &quot;test2&quot;, 10000);
}
else{
MessageBox(NULL, &quot;Function not found&quot;, &quot;Error!&quot;, MB_OK);
}
}
else{
MessageBox(NULL, &quot;Library not found&quot;, &quot;Error!&quot;, MB_OK);
}
FreeLibrary(hLib);
}



****************************
The message containing &quot;Function not found&quot; is shown to me whick means that the program is unable to find my function... Does anyone has a suggestion?
thanks
****************************
 
I've changed the name of my function in the getProcAddress function by the weird name that we find in the quickview

?CreateGauge@@YAXPBD0H@Z

... and it work...

but if someone know a better way to do this... just tell me.

thanks.
 
Ok:
Define function like this:

extern &quot;C&quot;
int _declspec(dllexport)
XXL_Identify(
unsigned char* name,
unsigned char* description,
unsigned char* version
)

You will need to add in .DEF file something like this:
XXL_Identify @1


In main application to the following:

1)
typedef int (*F_XXL_Identify)(unsigned char* name, unsigned char* description, unsigned char* version);

2)
F_XXL_Identify Function_XXL_Identify;

3)
Function_XXL_Identify = (F_XXL_Identify)::GetProcAddress(DLLHandle,_T(&quot;XXL_Identify&quot;));

4) Now you can call the function like this:
Function_XXL_Identify(&quot;sasa&quot;, &quot;car&quot;, &quot;1&quot;);


=== Hope this helps ===
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top