-
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???
Alexander Hotmar
-
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.
Danny Kalev
-
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???
Alexander Hotmar
-
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.
Alexander Hotmar
-
CALLBACK is a macro that disguises a certain calling convention (__pascal? __stdcall) so it is a calling convention mismatch.
Danny Kalev
Similar Threads
-
By Patrick Troughton in forum .NET
Replies: 78
Last Post: 08-13-2002, 11:18 AM
-
Replies: 0
Last Post: 07-20-2002, 10:12 PM
-
Replies: 5
Last Post: 04-08-2002, 09:19 AM
-
Replies: 1
Last Post: 02-28-2002, 12:54 AM
-
By Michael Shutt in forum VB Classic
Replies: 6
Last Post: 04-05-2001, 02:25 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks