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:
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???
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.
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.
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 *);
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???
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.
CALLBACK is a macro that disguises a certain calling convention (__pascal? __stdcall) so it is a calling convention mismatch.
By Patrick Troughton in forum .NET
Last Post: 08-13-2002, 12:18 PM
Last Post: 07-20-2002, 11:12 PM
Last Post: 04-08-2002, 10:19 AM
Last Post: 02-28-2002, 01:54 AM
By Michael Shutt in forum VB Classic
Last Post: 04-05-2001, 03:25 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL