Problem with calling a function from dll
I want to call a function. It is in one dll, I get the Handle to dll and get the function with GetProcAddress but the type of the returned pointer to function is int (__stdcall *p)(void). My function have a parameters, I cast with:
p_of_my_type=(p_of_my_type)GetProcAddress(HANDLE,"My_function");
and then call the function, but an error occured:
"The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling conversion with function pointer declared with a different calling conversion."
What is ESP and where is the problem?
[633 byte] By [
hotmar] at [2007-11-11 7:20:14]

# 1 Re: Problem with calling a function from dll
ESP is a cpu register (extended stack pointer?)
Your dll and c++ are not speaking the same language, you will have to read the help on calling conventions.
jonnin at 2007-11-11 21:02:23 >

# 2 Re: Problem with calling a function from dll
Ignore ESP, simply make sure that your function has the right signature, including the right calling convention. BTW, this error could occur if there's a mismatch between the parameter lists of the DLL's function and the pointer.
Danny at 2007-11-11 21:03:23 >

# 3 Re: Problem with calling a function from dll
I do that but the error is not here I think. This is my code only a few line:
typedef unsigned long (*tTransIP)(char *);
unsigned long(*pTransIP)(char *);
HINSTANCE h_ws2_32;
h_ws2_32 = LoadLibrary("ws2_32.dll");
pTransIP = (tTransIP) GetProcAddress(h_ws2_32, "inet_addr");
pTransIP("192.168.1.74"); //error occurs in this line
The declaration of the function is:
unsigned long inet_addr (
const char FAR * cp
);
Where is an error?
hotmar at 2007-11-11 21:04:32 >

# 4 Re: Problem with calling a function from dll
I found the error, the declaration of the pointer to function need "CALLBACK":)
If something kill the C and C++ that will be stuped problems like this. Thanks for support.
hotmar at 2007-11-11 21:05:33 >
