Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What wrong happened in my simple dll?

What wrong happened in my simple dll?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kabashiro
    wrote on last edited by
    #1

    ----------------- TestDll.h ----------------- #ifdef __cplusplus #define EXPORT extern "C" __declspec (dllexport) #else #define EXPORT __declspec (dllexport) #endif EXPORT BOOL Test1(BOOL b1); ----------------- TestDll.c ----------------- #include "SocketDll.h" int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { return TRUE; } EXPORT BOOL Test1(BOOL b1) { return b1; } ====================================================== When my application calls the Test1() function, error occurred. It reports : ----------------------------------------------------------------- file: i386\chkesp.c line:42 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 convention with a function pointer declared with a different calling convention. ----------------------------------------------------------------- But if the Test1() function has no argument, it works. I don't know how to correct it.

    R 1 Reply Last reply
    0
    • K Kabashiro

      ----------------- TestDll.h ----------------- #ifdef __cplusplus #define EXPORT extern "C" __declspec (dllexport) #else #define EXPORT __declspec (dllexport) #endif EXPORT BOOL Test1(BOOL b1); ----------------- TestDll.c ----------------- #include "SocketDll.h" int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { return TRUE; } EXPORT BOOL Test1(BOOL b1) { return b1; } ====================================================== When my application calls the Test1() function, error occurred. It reports : ----------------------------------------------------------------- file: i386\chkesp.c line:42 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 convention with a function pointer declared with a different calling convention. ----------------------------------------------------------------- But if the Test1() function has no argument, it works. I don't know how to correct it.

      R Offline
      R Offline
      Robert Kuster
      wrote on last edited by
      #2

      > When my application calls the Test1() function, error occurred. > It reports : > ----------------------------------------------------------------- > file: i386\chkesp.c line:42 > 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 convention with a function pointer declared with > a different calling convention. Hm...maybe you compiled your EXE with a different calling convention than your DLL? In VC6, check the following: Project -> Settings (or Alt+F7) -> C/C++ Tab -> Category: Code Generation -> Calling Convention You can also modify the calling convention of each function individually; i.e., try out all the combinations:

      EXPORT BOOL __stdcall Test1(BOOL b1) { return b1; }
      EXPORT BOOL __cdecl Test1(BOOL b1) { return b1; }
      EXPORT BOOL __fastcall Test1(BOOL b1) { return b1; }

      > When my application calls the Test1...() Anyway, is your EXE a VB application? Then you'll have to declare the exported function with __stdcall. It's the only calling convention known by VB. Regards, RK

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups