DLL bzw Plugin
-
Hallo
Ich habe ein Programm das Daten ......
Nun möchte ich neue Funktionen in Form einer DLL (Plugin) hinzufügen.Frage:
Wie schreibe ich mein Prog. um das es zB. Beim Start alle DLLs findet; dann die MenüEinträge ändert und dann auch noch die vorhandenen Funktionen auf Menü-Click ausführt?Ohne das Header,DEF oder LIB Datei der DLL in das Programm eingebunden sind!
-
LoadLibrary, GetProcAddress, etc.
-
Schnelle Antwort:
ist mir schon Klar:
Main.ctypedef void (*function1_ptr) (); static function1_ptr function1=NULL; HMODULE hm = LoadLibrary("dll.dll"); if(hm) function1 = (function1_ptr)GetProcAddress (hm,"_DllFunction1@4");dll.cEXPORT void DllFunction1(LPSTR message)Nun in diesem Fall kenne ich ja den FunktionsNamen
aber wenn nicht?
Wie bekomme ich die Funktion und die Parameter?
-
Wie meinst du das? Du mußt dir halt eine Schnittstelle ausdenken für dein Pluginsystem. Eine Plugin DLL muss dann Funktionen mit festgelegten Namen und Signaturen exportieren, die dein Programm dann mit GetProcAddress laden kann.
-
Meinte das so in etwa so
http://www.codeproject.com/KB/DLL/Execute_DLL_Function.aspx
verstehe leider kein c++
-
Naja was der Typ da macht hört sich nach ziemlichem Gehacke an, davon würde ich eher abraten. Aber die grundlegenden Schritte, die du durchführen musst, beschreibt er ja gleich am Anfang
* Load the DLL: Since LoadLibrary has LPCTSTR type parameter for DLL name to load, just get string input from user and pass to it.
* Get the function pointer: Here also, GetProcAddress has LPCTSTR type parameter for function name to pass, get string input from user and pass to it.
* Pass the parameters: Here comes the problem. Compiler, in most cases, passes arguments to function through stack. Try to simulate the compiler, get the parameter types from user in addition to the parameter values. Align & push the parameters in to the stack.
* Call the function: jump to the function using the function pointer that is obtained through GetProcAddress.
* Get the return value: Get the return type from user. Function always returns 32 bit value (except in 64 bit applications) in a register. Get this value and type cast into the type specified by the user.