Menu

Which Format of Extern/Dll ref is good 4 Dev

stev
2008-10-09
2012-09-26
  • stev

    stev - 2008-10-09

    Hi,

    Thanks again for help on another thread.

    I have 2 questions.
    (1) The first about the correct format of dll referencing in an include file for Dev C++.
    (2) The Second about correctly calling those functions in the code.

    Here's the first question.

    I'm examining the EXECryptor sample code created for CBuilder, LCC and MSVC.
    I notice a difference in the format of referencing those dll functions in the include files.

    In the include sample for MSVC, the code is written like this.

    [code]
    declspec(dllexport) bool stdcall EXECryptor_IsAppProtected();
    declspec(dllexport) const char * stdcall EXECryptor_GetEXECryptorVersion();
    void GetReleaseDate(int Day, int Month, int Year);
    void SafeGetDate(int
    Day, int Month, int Year);
    declspec(dllexport) DWORD stdcall EXECryptor_GetHardwareID();
    [/code]

    In the CBuilder sample, the include code is written like this

    [code]
    bool _stdcall _export EXECryptor_IsAppProtected();
    const char * _stdcall _export EXECryptor_GetEXECryptorVersion();
    void GetReleaseDate(int Day, int Month, int Year);
    void SafeGetDate(int
    Day, int Month, int Year);
    DWORD _stdcall _export EXECryptor_GetHardwareID();
    [/code]

    In the LCC sample, the include code uses this format
    [code]

    define EXECRYPTORAPI __declspec(dllexport) _stdcall

    extern bool EXECRYPTORAPI EXECryptor_IsAppProtected(void);
    extern const char EXECRYPTORAPI * EXECryptor_GetEXECryptorVersion(void);
    extern void GetReleaseDate(int Day, int Month, int *Year);

    extern void SafeGetDate(int Day, int Month, int *Year);
    extern DWORD EXECRYPTORAPI EXECryptor_GetHardwareID();

    [/code]
    Which if any of these codes is the correct format for use with Dev 4992?


    Here's the Second Question - it's related.

    After I get the include file format right, what is the correct way to call those functions from my code?
    For example let's say I want to call EXECryptor_IsAppProtected();? I tried just calling it and it couldn't find it with both the LCC and MSVC example and got the compiler error (undefined reference error. )

    In my code do I have to do something special ? like launch an instance of the dll? I don't see them doing that in their sample code.

    Thanks a MILLION.

    I Did not know how much there is to know about C++

    Thanks
    Stephen

     

    Related

    Code: code

    • cpns

      cpns - 2008-10-10

      "undefined reference" is not a compiler error. It is a linker error. In most cases a DLL has an associated export library with a .a extension. You have to link that to your code.

      The export library is compiler specific and you cannot (without upgrading the compiler to GCC 4.x) use an MSVC++ export library with MinGW/GCC 3.4.2 (the compiler that Dev-C++ uses by default).

      Since you apparently compiled your code (because linking occurs after compilation) then the header file is most likely OK since that is parsed by teh compiler.

      If you don't have a suitable export library an MS export library (which will have .lib extension) can be converted using the reimp tool, or you can use LoadLibrary/GetProcAddress to get teh library entry points programatically.

      This may help: http://sourceforge.net/forum/message.php?msg_id=2670009

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.