Reputation:
I want to draw text to a DirectX game, so I've injected a DLL which hooks EndPaint. My logic was that since EndPaint is supposed to be the last step in the WM_PAINT operation, I could, in my hook, draw the text, and then call EndPaint myself. By doing this, I avoid the DX interface altogether.
The problem is that it is doing absolutely nothing. Here is my code.
#include <windows.h>
#include "Hooks.h"
static const TCHAR g_cszMessage[] = TEXT("utterly fantastic");
BOOL (WINAPI * _EndPaint)(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint) = EndPaint;
BOOL WINAPI EndPaintHook(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint)
{
// write message
TextOut(lpPaint->hdc, 0, 0, g_cszMessage, lstrlen(g_cszMessage));
GdiFlush();
// return original
return _EndPaint(hWnd, lpPaint);
}
BOOL APIENTRY DllMain(__in HINSTANCE hModule, __in DWORD fdwReason, __in __reserved LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (AttachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook))
{
DisableThreadLibraryCalls(hModule);
break;
}
return FALSE;
case DLL_PROCESS_DETACH:
DetachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook);
break;
}
return TRUE;
}
I know the issue isn't with my AttachHook
/DetachHook
functions because I've tested via message boxes and confirmed that the hooks are installed. The text simply isn't showing up.
Anyone have any idea? I don't really want to hook the DX interface. Shouldn't it work either way, since WM_PAINT is still used at the base level?
Thanks in advance.
Upvotes: 1
Views: 1212
Reputation: 62333
You are better off hooking the present of DirectX and then using ID3DXFont to do some font rendering. AFAIK WM_PAINT is not used for DirectX rendering.
Upvotes: 1