Probleme mit DLL
-
ich habe eine DLL erdtellt und bekomme es einfach nich hin, eine Funktion aus dieser DLL anzusprechen. Um das ganz simpel zu halten, habe ich eine Funktion integriert die eine Messagebox ausgibt.
Hier erstmal der DLL-Code:
BOOL MsgBox(HWND hWindow); BOOL MsgBox(HWND hWindow) { MessageBox(hWindow, "Die ist ein Test-Text", "Test-Text", MB_OK) return TRUE; }
Wenn ich nun versuche diese Funktion zu benutzen bekomme ich immer NULL als Ergebnis.
typedef (*TESTTEXT) (HWND); INSTANCE hDLL; TESTTEXT MsgBox; hDLL = LoadLibary("DLLName"); MsgBox = (TESTTEXT)GetProcAdress(hDLL, "MsgBox")
MsgBox ist NULL; Ich habe ne menge rumprobiert und MsgBox ist immer NULL.
Für Hilfe wäre ich sehr dankbar.
-
Ich denke export sollte dein Stichwort sein
Schau dir auch mal den Beitrag in den FAQ an, oder benutz die Forensuche
-
So müßte es funktionieren
//MsgDll.h #ifndef MSGDLL_H #define MSGDLL_H #include <windows.h> #ifdef MSGDLL_EXPORTS #define MSGDLLAPI __declspec(dllexport) #else #define MSGDLLAPI __declspec(dllimport) #endif MSGDLLAPI BOOL MsgBox(HWND); #endif /*MSGDLL_H*/ //MsgDll.c oder MsgDll.cpp #define MSGDLL_EXPORTS #include "MsgDll.h" MSGDLLAPI BOOL MsgBox(HWND hWindow) { MessageBox(hWindow, "Die ist ein Test-Text", "Test-Text", MB_OK) return TRUE; } //Main.c oder Main.cpp /*** Das kannst Du auch weglassen */ /* --> */ #ifdef MSGDLL_EXPORTS #undef MSGDLL_EXPORTS #endif /* <-- */ #include "MsgDll.h" // ... typedef BOOL (*DllFunc)(HWND); HINSTANCE hDLL; DllFunc MsgBox; hDLL = LoadLibary("DLLName"); MsgBox = (DllFunc) GetProcAdress(hDLL, "MsgBox")
-
Ach ja, so geht es dann natürlich noch viel einfacher:
//MsgDll.h //wie oben //MsgDll.c oder MsgDll.cpp //wie oben //Main.c oder Main.cpp /*** Das kannst Du auch weglassen */ /* --> */ #ifdef MSGDLL_EXPORTS #undef MSGDLL_EXPORTS #endif /* <-- */ #include "MsgDll.h" // ... //typedef BOOL (*DllFunc)(HWND); //Unnoetig! HINSTANCE hDLL; //DllFunc MsgBox; //Unnoetig! hDLL = LoadLibary("DLLName"); MsgBox(hMainWnd);