我的DLL
#include <windows.h>
#include <vector>
#include "Funkcje.h"
WNDPROC originalProc;
LRESULT CALLBACK myHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwreason,
LPVOID lpReversed)
{
switch (fdwreason)
{
case DLL_PROCESS_ATTACH:
WNDPROC originalProc = SetWindowLongPtr(getToplevelWindows()[1], GWLP_WNDPROC, (LONG_PTR)myHookProc);
break;
}
return TRUE;
}
LRESULT CALLBACK myHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT originalResult = originalProc(hWnd, uMsg, wParam, lParam); // call original first
if (uMsg == WM_PAINT)
{
PAINTSTRUCT ps;
HDC hdc = GetDC(hWnd);
TextOut(hdc, 150, 150, L"TEST", 4);
ReleaseDC(hWnd, hdc);
}
return originalResult;
}
Funkcje.h http://pastebin.com/dc5t5H8s
我遇到了(LONG_PTR)myHookProc的问题 我的编译器说错误C2440:'初始化':无法从'LONG'转换为'WNDPROC' 我不知道我现在能做什么。没有(LONG_PTR)我的编译器说他不能从'LRESULT'转换为'LONG'
答案 0 :(得分:1)
将签名更改为:
LRESULT APIENTRY myHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
致电:
WNDPROC originalProc = (WNDPROC)SetWindowLongPtr(getToplevelWindows()[1], GWLP_WNDPROC, (LONG_PTR)myHookProc);