Komme nicht mehr weiter... DLL ;-(



  • Hi Leute,
    wo ist der Fehler?

    DLL:
    Header Datei:

    #ifndef _jobheader_
    #define _jobheader_
    
    #ifdef __cplusplus 
    extern "C" {   
    #endif 
    #if _USRDLL
    GUID __declspec(dllexport) getJobId(void);
    int __declspec(dllexport) getInt(void);
    int __declspec(dllexport) getSub(int one, int two);
    #else
    GUID __declspec(dllimport) getJobId(void);
    int __declspec(dllimport) getInt(void);
    int __declspec(dllimport) getSub(int one, int two);
    #endif
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif
    

    Die cpp Datei:

    #include "JobHeader.h"
    ...
    extern "C" GUID getJobId(void)
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState());
    	// {E038C148-69C7-41f1-AD90-06156A790120}
    	static const GUID id = 
    		{ 0xe038c148, 0x69c7, 0x41f1, { 0xad, 0x90, 0x6, 0x15, 0x6a, 0x79, 0x1, 0x20 } };
    	return id;
    }
    
    extern "C" int getInt(void)
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState());
    	return 100;
    }
    
    extern "C" int getSub(int one, int two)
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState());
    	return (one-two);
    }
    

    Lesen der DLL im Mainprog:

    typedef GUID (WINAPI * PFNGETJOBID)(void);
    		typedef int (WINAPI * PFNGETINT)(void);
    		typedef int (WINAPI * PFNGETSUB)(int, int);
    		HINSTANCE hLib;
    		PFNGETJOBID pfnGetJobId;
    		//PFNGETSUB pfnGetSub;
    
    		hLib = LoadLibrary(appPath);
    		if(hLib)
    		{
    			pfnGetJobId = (PFNGETJOBID)GetProcAddress(hLib, "_getJobId");
    			if(pfnGetJobId)
    			{
    				GUID t = pfnGetJobId();
    				AfxMessageBox("jup geladen!");
    			}		
    			else
    			{
    				AfxMessageBox("Scheisse!");
    				DWORD err = GetLastError();
    			}
    			FreeLibrary(hLib);
    		}
    

    Ich bekomme dabei immer einen RunTimeCheck Failure oder so...
    Er scheint die Function nicht zu finden...
    Ich sitzte jetzt schon Stunden daran und kann die Ursache nicht finden...

    Kann mir jemand helfen (bitte ohne link auf die anderen DLL Posts, habe schon alle durchgekämmt)



  • achso sorry
    muss natürlich

    pfnGetJobId = (PFNGETJOBID)GetProcAddress(hLib, "getJobId");
    

    lauten!!!



  • funzt aber trotzdem nicht...

    Hoffentlich sieht jemand mehr als ich 🙄



  • GetProcAddress() liefert aber was zurück was nicht NULL ist ?



  • Ich muss sagen, ich blicke durch deine Präcompiler-Direktiven nicht durch. Ganz sicher, dass das alles so richtig ist?



  • @geeky
    GetProcAddress() liefert aber was zurück was nicht NULL ist ?

    Ja zumindest ist das Ergebnis ungleich NULL. Nur beim Aufruf der Funktionen samt Parameter kommt es zum Absturz.

    @WebFritzi
    Die Direktiven habe ich aus dem Buch von Frank Budszuhn (VS C++ + MFC)...

    ....



  • Hier die Fehlermedlung:

    Run-Time check failure #0 - The value was not properly saved across a function call...

    Kann mir denn keiner weiter helfen ??? 😕 😞



  • 😃
    Okay Leute habe es selber gefunden... OH MANN!!! Wer lesen kann ist klar im Vorteil!!!

    Problem war folgendes:
    In der Header Datei war die Funktion folgender Maßen deklariert:

    int __declspec(dllexport) getSub(int one, int two);
    

    Man beachte __declspec(dllexport)!

    In mein Mainprog habe ich habe den Aufruf als

    typedef int (WINAPI * PFNGETSUB)(int, int);
    

    definiert. Tja nur ist WINAPI als __stdcall definiert...

    Alles klar? Muss man als Newbie erstmal drauf kommen... 🕶


Anmelden zum Antworten