Aufrufen einer funktion



  • Wie kann ich aus einer Dll eine Funktion in meinem hauptprogramm aufrufen?
    Muss ich da noch was deklarieren?



  • [edit]ups hab die frage flasch gelesen... [/edit]



  • // LOL.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "Windows.h"
    
    typedef (*PFN_DLL_LOL)(void);
    
    extern "C" __declspec(dllexport) void LOL_ExeFunktion( void )
    {
    	printf("LOL!\n");
    }
    
    int main(int argc, char* argv[])
    {
    	PFN_DLL_LOL pfnLOLFunktion;
    
    	HMODULE hMod = LoadLibrary("LOL");
    
    	if( !hMod )
    		printf("LOL Konnte DLL nicht laden LOL!\n");
    
    	if( !(pfnLOLFunktion = (PFN_DLL_LOL)GetProcAddress( hMod, "LOL_DllFunktion" )) )
    		printf("LOL Geht nich LOL!\n");
    
    	pfnLOLFunktion();
    
    	FreeLibrary(hMod);
    	return 0;
    }
    
    // LOL2.cpp : Defines the entry point for the DLL application.
    //
    
    #include "stdafx.h"
    
    typedef (*PFN_EXE_LOL)(void);
    
    extern "C" _declspec(dllexport) void LOL_DllFunktion( void )
    {
    	PFN_EXE_LOL pfnLOLFunktion = (PFN_EXE_LOL) GetProcAddress( GetModuleHandle(0), "LOL_ExeFunktion" );
    
    	if( !pfnLOLFunktion )
    		return; // LOL!
    
    	pfnLOLFunktion();
    }
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {
        return TRUE;
    }
    


  • Danke für die Antwort. Das was lol hingeschrieben hat mach ich nicht. Mein
    Compiler generiert eine Statische lib gleich mmit. Jetzt mach ich es halt über ne Datei.
    Also
    Program>>DLL>>DATEI>>Program
    Geht ja so.

    Trotzdem Danke.


Anmelden zum Antworten