Hi guys, i made a .dll file ,and tried to use LoadLibrary() and GetProcAddress() to get the functions in .dll, but due to the calling conventions ,i failed to do this with all the functions,pls help
[tag]some snippets in mydll.cpp for mydll.dll[/tag]
Code:
.
...
....
......
extern "C" _declspec(dllexport) void echo1(){};
extern "C" _declspec(dllexport) void _stdcall echo2(){};
_declspec(dllexport) void echo3(){};
_declspec(dllexport) void _stdcall echo4(){};
......
....
..
.
i built it and got a mydll.dll file, then tried to use it in anoter .cpp file, but some wrong happened in calling GetProcAddress(),listing below:
[tag].cpp using functions in mydll.dll [/tag]
Code:
#include <windows.h>
#include "stdio.h"
int main(int argc, char** argv)
{
HMODULE hDll;
hDll = (HMODULE)LoadLibrary("my.dll");
typedef void(FAR *MyEcho1)();
MyEcho1 myecho1;
myecho1 = (MyEcho1)GetProcAddress(hDll,"echo1");
if(!myecho1)
{printf("Can't find func!");}
else
myecho1(); // function called successful
typedef void(FAR *MyEcho2)();
MyEcho2 myecho2;
myecho2= (MyEcho2)GetProcAddress(hDll,"echo2");
if(!myecho2)
{printf("Can't find func!");}
else
myecho2(); // function called successful
typedef void (FAR _cdecl *MyEcho3)(); // here is the problem, i think
MyEcho3 myecho3;
myecho3= (MyEcho3)GetProcAddress(hDll,"echo3");// Problem happened here
if(!myecho3)
{printf("Can't find func!\n");} //so printed error!
else
myecho3();
typedef void (FAR _stdcall *MyEcho4)(); //this block has same problem with upper one
MyEcho4 myecho4;
myecho4= (MyEcho4)GetProcAddress(hDll,"echo4");
if(!myecho4)
{printf("Can't find func!\n")};
else
myecho4();
FreeLibrary(hDll);
return 0;
}
[tag]wrong code,how can i do it in a right way?[/tag]
Code:
typedef void (FAR _cdecl *MyEcho3)();
typedef void (FAR _stdcall *MyEcho4)();
i know that without extern "C", c++ complier(using code::blocks, but compliser is MS VC++2005/2008) changed the name of echo3 and echo4. i don't want a .DEF file, how can i make it and call it with LoadLibrary() and GetProcAddress(), thanks!