Trying to write a GLOBAL CBT HOOK,
this is My code, but my hooking app doesn't recieve any Messages, neither writes the dll something to a test file.
This is My Code:
#include "stdafx.h"
#include "GlobalHook.h"
#include "Stdafx.h"
#include <iostream>
#include <fstream>
#define DLL_EXPORT
#include "GlobalHook.h"
#include <windows.h>
using namespace std;
#pragma comment(lib, "User32.lib")
#pragma unmanaged
HINSTANCE dllHandle;
#pragma data_seg("ASEG")
HWND prnt = 0;
#pragma data_seg()
#pragma comment(linker, "/section:ASEG,RWS")
HHOOK hHook;
int x = 0;
BOOL APIENTRY DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
PVOID lpReserved ) // reserved
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
dllHandle = hinstDLL;
return TRUE;
break;
}
}
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode < 0)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
if(nCode == HCBT_MINMAX)
{
SendNotifyMessage(prnt, WM_USER + 3, wParam, lParam);
if(x == 0)
{
ofstream myfile;
myfile.open ("C:\\example.txt");
myfile << "Dies in ein File.";
myfile.close();
x = 1;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
extern "C"
{
DECLDIR int SetHook( HWND parent )
{
prnt = parent;
hHook = SetWindowsHookEx(WH_CBT, CBTProc, dllHandle, 0);
return 1;
}
DECLDIR void UninstallHook( void )
{
if(UnhookWindowsHookEx(hHook))
{
}
}
DECLDIR int Add(int a, int b)
{
return (a + b);
}
}