Problem with calling a function from dll


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Problem with calling a function from dll

  1. #1
    Join Date
    Mar 2004
    Location
    Bulgaria
    Posts
    14

    Question 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

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    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.

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    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

  4. #4
    Join Date
    Mar 2004
    Location
    Bulgaria
    Posts
    14

    Question

    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

  5. #5
    Join Date
    Mar 2004
    Location
    Bulgaria
    Posts
    14

    Talking

    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

  6. #6
    Join Date
    Nov 2003
    Posts
    4,118
    CALLBACK is a macro that disguises a certain calling convention (__pascal? __stdcall) so it is a calling convention mismatch.
    Danny Kalev

Similar Threads

  1. VB6 vs VB.NET...Procedure Calling Syntax
    By Patrick Troughton in forum .NET
    Replies: 78
    Last Post: 08-13-2002, 11:18 AM
  2. Replies: 0
    Last Post: 07-20-2002, 10:12 PM
  3. dll problem
    By James in forum .NET
    Replies: 5
    Last Post: 04-08-2002, 09:19 AM
  4. Replies: 1
    Last Post: 02-28-2002, 12:54 AM
  5. calling ping thru vb
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center