tag'chen.
ich wollte mich eigentlich erst mal an etwas ganz leichtes ran machen, und zwar mit einen hook die WM_QUIT message eines processes abfangen.
hier mal die DLL.
und hier die anwendung die den hook in einem anbderen setzen soll
also das problem ist: er fliegt IMMER bei "Hooking failed " raus.
GetLastError() sagt, "Falscher Parameter"
die dll lade ich statisch ins project, die dllmain wird auch durchlaufen
ich weiss echt nicht wo es hackt...
Gruß Tobi.
ich wollte mich eigentlich erst mal an etwas ganz leichtes ran machen, und zwar mit einen hook die WM_QUIT message eines processes abfangen.
hier mal die DLL.
Code:
/*******************************************************************************
File : funcDLL.cpp
Remark : This file contains definitions of hook function.
*******************************************************************************/
//--- Includes -----------------------------------------------------------------
#include <windows.h>
#include "funcDLL.h"
//--- Globals ------------------------------------------------------------------
#pragma argsused
HINSTANCE hDLLInst;
HHOOK hHook;
//--- Prototypes ---------------------------------------------------------------
LRESULT CALLBACK MessageProc( int, WPARAM, LPARAM );
//--- DllMain ------------------------------------------------------------------
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved) {
switch( fwdreason ) {
case DLL_PROCESS_ATTACH: {
hDLLInst = hinstDLL;
break;
}
case DLL_THREAD_ATTACH: {
break;
}
case DLL_PROCESS_DETACH: {
break;
}
case DLL_THREAD_DETACH: {
break;
}
}
return true;
}
//--- Definition ---------------------------------------------------------------
LRESULT CALLBACK MessageProc( int nCode, WPARAM wParam, LPARAM lParam ) {
MSG *msg = (MSG*)lParam;
switch( msg->message ) {
case WM_QUIT: {
MessageBox( 0, "WM_QUIT was hooked :)", "Atantion!", MB_OK | MB_ICONERROR );
break;
}
}
return( CallNextHookEx( hHook, nCode, wParam, lParam ) );
}
EXPORT bool setHook( DWORD processID ) {
hHook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)MessageProc, hDLLInst, processID );
if( !hHook ) {
return false;
}
return true;
}
EXPORT bool removeHook( ) {
if( ( UnhookWindowsHookEx( hHook ) ) == 0 ) {
return false;
}
return true;
}
//--- EXIT ---------------------------------------------------------------------
und hier die anwendung die den hook in einem anbderen setzen soll
Code:
//--- Includes -----------------------------------------------------------------
#include <windows.h>
#include <iostream>
#include <conio.h>
#include "funcDLL.h"
using namespace std;
//--- Globals ------------------------------------------------------------------
#pragma hdrstop
#pragma argsused
#define ESCAPE 27
char szWindowName[ 128 ];
HWND hWnd;
DWORD dwProcessID;
int vKey;
//--- Prototypes ---------------------------------------------------------------
//--- Main ---------------------------------------------------------------------
int main(int argc, char* argv[]) {
cout << " Enter the name of running window, which you want to hook!" << endl;
cout << " WindowName : ";
cin.getline( szWindowName, sizeof( szWindowName ) );
hWnd = FindWindow( 0, szWindowName );
if( !hWnd ) {
cout << "\n\n Couldn't found window named \"" << szWindowName << "\".";
Sleep( 2000 );
return 0;
}
GetWindowThreadProcessId( hWnd, &dwProcessID );
if( (setHook( dwProcessID ) ) ) {
cout << "\n\n The MessageHook was successful loaded in process of \"" << szWindowName << "\".";
}
else {
cout << "\n\n Hooking failed!";
Sleep( 2000 );
return 0;
}
cout << "\n\n To unhook the prcoess press escape ...";
do {
if( kbhit( ) ) {
vKey = getch( );
}
} while( vKey != ESCAPE );
if( ( removeHook( ) ) ) {
cout << "\n\n The MessageHook was successful removed from process of \"" << szWindowName << "\".";
}
else {
cout << "\n\n The MessageHook couldn't successfully removed from process of \"" << szWindowName << "\".";
}
Sleep( 2000 );
return 0;
}
//--- Definitions --------------------------------------------------------------
//--- EXIT ---------------------------------------------------------------------
GetLastError() sagt, "Falscher Parameter"
die dll lade ich statisch ins project, die dllmain wird auch durchlaufen
ich weiss echt nicht wo es hackt...
Gruß Tobi.