Dynamic Link Library (DLL) - Problem



  • Hi!

    ich eigne mir gerade DLL programmierung an, mittels der programmiersprache C++.
    irgendwie klappt das noch nicht so ganz. eventuell weis jemand warum. ich poste mal den EXE code und den DLL code.

    EXE

    #include "windows.h"
    
    typedef void (*Function1Proc)(char *Msg, int ID);
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
        HMODULE MyLib; 
    	Function1Proc runDLLFunction1 = NULL;
    
    	MyLib = LoadLibrary("hm.dll");
    
        if(MyLib == NULL)
    	{ 
            MessageBox(NULL,"DLL nicht gefunden!","Haupt Programm",16); 
            return 1; 
        } 
    
        runDLLFunction1 = (Function1Proc)GetProcAddress(MyLib, "_Function1");
    
        if(runDLLFunction1 == NULL)
    	{ 
            MessageBox(NULL,"DLL-Funktion nicht gefunden!","Haupt Programm",16); 
            return 2; 
        }
    
        runDLLFunction1("Hallo DLL Funktion. Hier sind wie erwartet deine zwei parameter",1); 
        FreeLibrary(MyLib); 
    
    	return 0;
    }
    

    DLL

    #include <windows.h>
    //..........................................................................
    #define DLL_Export __declspec(dllexport)
    //..........................................................................
    DLL_Export void Function1(char *Msg, int ID)
    {
    	MessageBox(NULL,Msg,"Function1",48);
    }
    //..........................................................................
    DLL_Export void Function2(char *Msg, int ID)
    {
    	MessageBox(NULL,Msg,"Function2",48);
    }
    //..........................................................................
    DLL_Export void Function3(char *Msg, int ID)
    {
    	MessageBox(NULL,Msg,"Function3",48);
    }
    //..........................................................................
    DLL_Export void Function4(char *Msg, int ID)
    {
    	MessageBox(NULL,Msg,"Function4",48);
    }
    //..........................................................................
    DLL_Export void Function5(char *Msg, int ID)
    {
    	MessageBox(NULL,Msg,"Function5",48);
    }
    //..........................................................................
    BOOL WINAPI DllMain(HINSTANCE hDllInst, DWORD fdwReason, LPVOID lpvReserved) 
    { 
    	switch (fdwReason)
    	{ 
    		case DLL_PROCESS_ATTACH: 
    		break; 
    
    		case DLL_PROCESS_DETACH: 
            break; 
    
    		case DLL_THREAD_ATTACH: 
            break; 
    
    		case DLL_THREAD_DETACH: 
            break; 
        } 
        return TRUE; 
    } 
    //..........................................................................
    

    Wenn ich nun die exe datei starte kommt die messagebox
    "DLL-Funktion nicht gefunden!" 😕 😕





  • typedef void (*Function1Proc)(char *Msg, int ID);
    

    muss

    typedef void (WINAPI* Function1Proc)(char *Msg, int ID);
    

    heissen.

    Mfg.



  • hallo daniel.
    danke für den tipp. irgendwie heisst die exportierte funktion nähmlich
    ?Function1@@YAXPADH@Z

    wenn ich das so nutze, geht es. hm


Anmelden zum Antworten