Probleme mit Konsole - dll
-
Ich habe ein Problem mit meiner Konsolen Anwendung.
Ich schreibe einen Chat der über Windows hooks funktioniert. Ich binde dazu eine .dll ein die auch den Hook erstellt (SetWindowsHookEx) Alle Parameter für einen korrekten globalen hokk sind gesetzt.
(WH_KEYBOARD,HookProc,hinstance,0)
Die variable hinstance ist eine Kopie des HINSTANCE Parameters der DllMain
Funktion.
Das Programm gibt den Fehler 1428(Kein ModulHandle spezifiziert) zurück.
Was kann ich tun?Ich kompiliere mit dev-CPP
P.S. habe schopn unter Namen masterfreek64 registriert
-
Dieser Thread wurde von Moderator/in SideWinder aus dem Forum DOS und Win32-Konsole in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
zeig doch mal wo der fehler auftritt und wo du das angeblich (nicht) korrekte handle setzt.
-
Also der code ist hier
int __declspec(dllexport)__stdcall makeHook(HWND window) { hkb = NULL; hWndServer = window; hkb = SetWindowsHookEx( WH_KEYBOARD, HookProc, hinstance, 0); if(hkb==NULL) { char err[10]; int Error = GetLastError(); sprintf(err, "%d", Error); MessageBox( NULL, "Couldn't create Hook", "Hook Error!", MB_OK); MessageBox( NULL, err, "Hook Error Code", MB_OK); return 0; } else return 1; }Das Programm gibt dann die beiden MessageBoxes aus. Also Couldn't create hook und dann 1428
hinsatnce kommt aus
BOOL APIENTRY DllMain(HINSTANCE handle, DWORD dwReason, LPVOID lpReserved)in DLLMAIN ist auch
if (dwReason == DLL_PROCESS_ATTACH) { // Init hinstance = handle; if(hinstance == NULL) { MessageBox(GetActiveWindow(), "Handle for dll was not received", "Error", MB_OK); } }HookProc sieht so aus:
LRESULT __declspec(dllexport)__stdcall CALLBACK HookProc(int nCode,WPARAM wParam, LPARAM lParam)Der Code kompiliert in Dev-CPP problemlos in VC nicht (Ich nehm nie VC, ist zu strikt und die headers machen immer Probleme (Doppeldefinition ) oder ne Bibliothek wird nicht gefunden , etc...
So das müsste euch helfen
-
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.Normalerweise du registrierst Funktion von der Hauptprogramme und spezifizierst hInstance von DLL. Wenn du von DLL hook registrierst, NULL fur hInstance ubergibt mussen.
Also hier ist ein gewisser unklar limitation:
Warning There are serious limits on what you can do in a DLL entry point. To provide more complex initialization, create an initialization routine for the DLL. You can require applications to call the initialization routine before calling any other routines in the DLL. Alternatively, the initialization routine can create a file with an ACL that restricts access, and each routine in the DLL would call the initialization routine if the file does not exist.
(C) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp
-
Ah danke
-
Nein funktioniert nicht immer noch Error .
Habe versucht Code aus FAQ zu nehmen aber der hat mein Winsock kaputtgemacht(ja danach kam ein WinSock Fehler)