Rundll32.exe und die entsprechende DLL
-
Hallo!
Folgendes hab ich in der MSDN gefunden:
Rundll32 The Run DLL utility (Rundll32.exe) included in Windows enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax: void CALLBACK EntryPoint( HWND hwnd, // handle to owner window HINSTANCE hinst, // instance handle for the DLL LPTSTR lpCmdLine, // string the DLL will parse int nCmdShow // show state ); Note that EntryPoint is a placeholder for the actual function name. For a list of possible show states, see WinMain. The following is the command-line syntax for Rundll32: rundll32 DllName,FunctionName [Arguments] DllName Specifies the name of the DLL. The name cannot contain spaces, commas, or quotation marks. The utility searches for the DLL using the search criteria documented for the LoadLibrary function. Therefore, it is best to use the short name and provide a full path for the DLL. FunctionName Specifies the name of the function to call in DllName. Requires a comma (without no spaces) between DllName and FunctionName. Arguments Optional arguments for FunctionName. Rundll32 loads the specified DLL using LoadLibrary, obtains the address of the function using the GetProcAddress function, and calls the function with the specified arguments, if any. When the function returns, Rundll32 unloads the DLL and exits. It is possible to create a Unicode version of the function. Rundll32 first tries to find a function namedEntryPointW. If it cannot find this function, it tries EntryPointA, then EntryPoint. To create a DLL that supports ANSI on Windows Me/98/95 and Unicode otherwise, export two functions: EntryPointW and EntryPoint.
Und hab das auch ma ausprobiert, aber es kommt immer eine Fehlermeldung: "Fehler in ... *.dll -- Folgender Eintrag fehlt:HW" (Was eigentlich gar nicht stimmt?! Mit rundll32.exe fdgdfg.dll,HW ausprobiert. Die MessageBox kommt auch noch zweimal, obwohl sie nur einmal kommen müsste???) Oder wie muss ich EntryPoint benutzen, weiß nich wie!
Hier der Quellttext:
// fdgdfg.cpp : Definiert den Einsprungpunkt für die DLL-Anwendung. // #include "stdafx.h" void HW(void) { MessageBox(NULL, "Hi!", "", MB_OK); } BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { HW(); return TRUE; }
Danke für Hilfe
Cu CaseModder
PS: @ MODI MSDN-Tag funktioniert nicht!!!
-
Hallo,
du mußt schon exakt den Beschreibungen, die du ja gefunden und angegeben hast, folgen. Da steht z.B.:
*These functions must have the following syntax:
void CALLBACK EntryPoint(
HWND hwnd, // handle to owner window
HINSTANCE hinst, // instance handle for the DLL
LPTSTR lpCmdLine, // string the DLL will parse
int nCmdShow // show state
);*aber du machst daraus:
void HW(void) { MessageBox(NULL, "Hi!", "", MB_OK); }
und das paßt überhaupt nicht zur geforderten Signatur der Funktion. Was du noch beachten mußt, steht hier:
http://support.microsoft.com/kb/q164787/
Damit kannst du aber nur etwas anfangen, wenn du schon mal DLLs programmiert hast, ansonsten noch ein Tutorial für DLLs hinzuziehen (wie werden Funktionen exportiert usw...).
Um auch noch die von dir beobachteten "Phänomene" zu klären (wie ich oben erklärt habe, ist dein Vorgehen völlig inkorrekt, warum erscheint dann trotzdem zweimal die MessageBox?):
RunDLL lädt die DLL, diese wird problemlos gefunden, beim Laden wird DllMain aufgerufen (1. MessageBox). Aber RunDLL entlädt auch die DLL wieder, bei einem solchen Vorgang (DLL_PROCESS_DETACH) wird auch wieder DLLMain aufgerufen (2. MessageBox).
Du hast damit also auf andere Weise die Funktion HW aufgerufen, aber nicht so, wie es für RunDLL gedacht ist. DLLMain hat nichts mit dem für RunDLL nötigen EntryPoint einer aufrufbaren Funktion zu tun.
MfG