15,473
社区成员




#pragma once
#define TEST_HOOK_API __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endif
TEST_HOOK_API DWORD SetHook();
#ifdef __cplusplus
}
#endif
#include <Windows.h>
#include "TestHook.h"
#pragma data_seg("TestData")
HHOOK g_hMouse;
HINSTANCE g_hInst=NULL;
#pragma data_seg()
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(g_hMouse, nCode, wParam, lParam);
}
DWORD SetHook()
{
g_hMouse = SetWindowsHookEx(WH_MOUSE, MouseProc, g_hInst, 0);
return GetLastError();
}
BOOL APIENTRY DllMain( HMODULE hModule,DWORD ul_reason_for_call, LPVOID lpReserved)
{
g_hInst = hModule;
return TRUE;
}
#include <stdio.h>
#include <Windows.h>
#include "../TestHook.h"
#pragma comment(lib, "TestHookDll.lib")
int main(int argc, char *argv[])
{
DWORD ret = SetHook();
printf("ret: %d\n", ret);
return 0;
}