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. DLL Question

DLL Question

Scheduled Pinned Locked Moved C / C++ / MFC
c++regexquestion
5 Posts 4 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.
  • S Offline
    S Offline
    Shay Harel
    wrote on last edited by
    #1

    Hi, I wrote a DLL which works fine if I just include the header file and the lib file in the code that uses this DLL. However, when I try to call functions from the DLL the program crash and complain about calling conventions that do not match. Here is the bare minimum: ******* DLL Code **** Header: typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *); SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK pfn); CPP file: SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK p_cbfn) { ..... } *** Client Code *** Header file: static void __cdecl SpcmCallBack (char *payload,pack_data *pd); CPP file: HISNT spcm_hInst =LoadLibrary (__TEXT("SpcmComm.dll"));//load the dll if (spcm_hInst) { PF_SPCMCOMMINIT initspcm;//pointer to the function initspcm = (PF_SPCMCOMMINIT) GetProcAddress spcm_hInst, "InitilizeConnection"); if (initspcm) { //*****this is where the code crash ***** int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack); }

    R S R 3 Replies Last reply
    0
    • S Shay Harel

      Hi, I wrote a DLL which works fine if I just include the header file and the lib file in the code that uses this DLL. However, when I try to call functions from the DLL the program crash and complain about calling conventions that do not match. Here is the bare minimum: ******* DLL Code **** Header: typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *); SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK pfn); CPP file: SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK p_cbfn) { ..... } *** Client Code *** Header file: static void __cdecl SpcmCallBack (char *payload,pack_data *pd); CPP file: HISNT spcm_hInst =LoadLibrary (__TEXT("SpcmComm.dll"));//load the dll if (spcm_hInst) { PF_SPCMCOMMINIT initspcm;//pointer to the function initspcm = (PF_SPCMCOMMINIT) GetProcAddress spcm_hInst, "InitilizeConnection"); if (initspcm) { //*****this is where the code crash ***** int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack); }

      R Offline
      R Offline
      Rick York
      wrote on last edited by
      #2

      does the library implementation have something like this in it ?

      extern "C"
      {
      }

      This needs to be around the prototype of InitilizeConnection in the header file and around its implementation in the .CPP file.

      S 1 Reply Last reply
      0
      • R Rick York

        does the library implementation have something like this in it ?

        extern "C"
        {
        }

        This needs to be around the prototype of InitilizeConnection in the header file and around its implementation in the .CPP file.

        S Offline
        S Offline
        Shay Harel
        wrote on last edited by
        #3

        Thanks, I will try that and let you know. In any case, what is the logic behind it and why does it work when I use the dll implicitly.

        1 Reply Last reply
        0
        • S Shay Harel

          Hi, I wrote a DLL which works fine if I just include the header file and the lib file in the code that uses this DLL. However, when I try to call functions from the DLL the program crash and complain about calling conventions that do not match. Here is the bare minimum: ******* DLL Code **** Header: typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *); SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK pfn); CPP file: SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK p_cbfn) { ..... } *** Client Code *** Header file: static void __cdecl SpcmCallBack (char *payload,pack_data *pd); CPP file: HISNT spcm_hInst =LoadLibrary (__TEXT("SpcmComm.dll"));//load the dll if (spcm_hInst) { PF_SPCMCOMMINIT initspcm;//pointer to the function initspcm = (PF_SPCMCOMMINIT) GetProcAddress spcm_hInst, "InitilizeConnection"); if (initspcm) { //*****this is where the code crash ***** int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack); }

          S Offline
          S Offline
          sunit5
          wrote on last edited by
          #4

          //int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack); aha! this is a callback function so the calling convention of both function has to be same but ",(PF_SPCMCOMM_CALLBACK)SpcmCallBack is _cedel where as initspcm is _stdcall. never say die

          1 Reply Last reply
          0
          • S Shay Harel

            Hi, I wrote a DLL which works fine if I just include the header file and the lib file in the code that uses this DLL. However, when I try to call functions from the DLL the program crash and complain about calling conventions that do not match. Here is the bare minimum: ******* DLL Code **** Header: typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *); SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK pfn); CPP file: SPCMCOMM_API int InitilizeConnection(char *appname,PF_SPCMCOMM_CALLBACK p_cbfn) { ..... } *** Client Code *** Header file: static void __cdecl SpcmCallBack (char *payload,pack_data *pd); CPP file: HISNT spcm_hInst =LoadLibrary (__TEXT("SpcmComm.dll"));//load the dll if (spcm_hInst) { PF_SPCMCOMMINIT initspcm;//pointer to the function initspcm = (PF_SPCMCOMMINIT) GetProcAddress spcm_hInst, "InitilizeConnection"); if (initspcm) { //*****this is where the code crash ***** int result=initspcm ("TestAlertUUT",(PF_SPCMCOMM_CALLBACK)SpcmCallBack); }

            R Offline
            R Offline
            Ryan Binns
            wrote on last edited by
            #5

            Shay Harel wrote:

            typedef void (__stdcall *PF_SPCMCOMM_CALLBACK)(char *,pack_data *);

            Shay Harel wrote:

            static void __cdecl SpcmCallBack (char *payload,pack_data *pd);

            These two must have the same calling convention - __stdcall and __cdecl are not compatible.

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            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