dll: grundlegende Fragen



  • Hi,
    ich bin dabei mal wieder was mit C++ zu machen.
    (Komme von Delphi)
    Dort habe ich schon ein paar mal mit dll gearbeitet.

    Nun möchte ich das gleiche auch mit c++.

    Also Tut gesucht! Tut gefunden!
    http://bcb-tutorial.c-plusplus.net/DLL_Tutorial/artikel5.html
    Leider ist das ein Builder Tutorial.

    Ich arbeite mit Dev C++.

    Nun verstehe ich zunächst nich, was

    BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                           DWORD reason        /* Reason this function is being called. */ ,
                           LPVOID reserved     /* Not used. */ )
    {
        switch (reason)
        {
          case DLL_PROCESS_ATTACH:
            break;
    
          case DLL_PROCESS_DETACH:
            break;
    
          case DLL_THREAD_ATTACH:
            break;
    
          case DLL_THREAD_DETACH:
            break;
        }
    
        /* Returns TRUE on success, FALSE on failure */
        return TRUE;
    }
    

    Diese Funktion macht?

    Thx schon mal für die Hilfe 😃

    MFG Ace





  • OK Thx.
    Noch ne Frage:
    Woher weiß das Programm welche DLL es einbinden soll, wenn ich die
    DLL so einbinde:

    //---------------------------------------------------------------------------
    __declspec (dllexport) int AddVals(int x, int y) //int __declspec(dllexport) AddVals(int x, int y)
    {
        return x + y;
    }
    //---------------------------------------------------------------------------
    __declspec (dllexport) int SubVals(int x, int y)
    {
        return x - y;
    }
    

    ??

    Und warum brauche ich einen Header?

    THX
    MFG Ace



  • [quote="AceKiller73"]Woher weiß das Programm welche DLL es einbinden soll, wenn ich die DLL so einbinde:

    __declspec (dllexport) int AddVals
    

    Hier bindest Du doch keine DLL ein! Sondern hier exportierst Du Funktionen!



  • Ahhh
    LOL
    falscher Code
    Ich meinte, wenn ich die Funktion im Header stehen hab.

    __declspec (dllexport) int AddVals(int, int); //Exportdeklaration in Header-Datei.
    

    Ich verstehe nicht ganz wie das funzt.
    In Delphi musst ich immer den Dll namen angeben.
    Muss ich hier doch bestimmt auch.
    Nur wo?

    MFG Ace



  • // The following ifdef block is the standard way of creating macros which make exporting 
    // from a DLL simpler. All files within this DLL are compiled with the TEST_EXPORTS
    // symbol defined on the command line. this symbol should not be defined on any project
    // that uses this DLL. This way any other project whose source files include this file see 
    // TEST_API functions as being imported from a DLL, wheras this DLL sees symbols
    // defined with this macro as being exported.
    #ifdef TEST_EXPORTS
    #define TEST_API __declspec(dllexport)
    #else
    #define TEST_API __declspec(dllimport)
    #endif
    
    TEST_API int fnTest(void);
    

    Du musst nicht den Namen der DLL irgendwo angeben. Wenn du die DLL erstellst, wird auch eine .lib Datei erstellt gegen die du dein Programm dann linkst.



  • Dumme Frage, aber wie linke ich die Datei.
    Unter Projekt>Optionen> und da dann weiter oder wie?
    Zudem finde ich keine Lib Datei.

    MFG Ace



  • Verwende folgendes im Code:

    #pragma comment(lib, "name-der.lib")
    

Anmelden zum Antworten