Detoursでcomdlg32.dllをフックしてみた。動く動く。
#include
#includestatic BOOL (WINAPI *TruePrintDlgA)(LPPRINTDLGA lppd) = PrintDlgA;
static BOOL (WINAPI *TruePrintDlgW)(LPPRINTDLGW lppd) = PrintDlgW;
static HRESULT (WINAPI *TruePrintDlgExA)(LPPRINTDLGEXA lppd) = PrintDlgExA;
static HRESULT (WINAPI *TruePrintDlgExW)(LPPRINTDLGEXW lppd) = PrintDlgExW;BOOL WINAPI DetourPrintDlgA(LPPRINTDLGA lppd)
{if(lppd != NULL){
lppd->Flags |= PD_RETURNDEFAULT;
lppd->hDevMode = NULL;
lppd->hDevNames = NULL;
}
return TruePrintDlgA(lppd);
}BOOL WINAPI DetourPrintDlgW(LPPRINTDLGW lppd)
{if(lppd != NULL){
lppd->Flags |= PD_RETURNDEFAULT;
lppd->hDevMode = NULL;
lppd->hDevNames = NULL;
}
return TruePrintDlgW(lppd);
}HRESULT WINAPI DetourPrintDlgExA(LPPRINTDLGEXA lppd)
{
HRESULT hres;if(lppd != NULL){
lppd->Flags |= PD_RETURNDEFAULT;
lppd->hDevMode = NULL;
lppd->hDevNames = NULL;
}hres = TruePrintDlgExA(lppd);
if(lppd != NULL) lppd->dwResultAction = PD_RESULT_PRINT;return hres;
}HRESULT WINAPI DetourPrintDlgExW(LPPRINTDLGEXW lppd)
{
HRESULT hres;if(lppd != NULL){
lppd->Flags |= PD_RETURNDEFAULT;
lppd->hDevMode = NULL;
lppd->hDevNames = NULL;
}hres = TruePrintDlgExW(lppd);
if(lppd != NULL) lppd->dwResultAction = PD_RESULT_PRINT;return hres;
}static void BeginMyDetours(void)
{DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID *)&TruePrintDlgA, DetourPrintDlgA);
DetourAttach((PVOID *)&TruePrintDlgW, DetourPrintDlgW);
DetourAttach((PVOID *)&TruePrintDlgExA, DetourPrintDlgExA);
DetourAttach((PVOID *)&TruePrintDlgExW, DetourPrintDlgExW);
DetourTransactionCommit();}
static void EndMyDetours(void)
{DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID *)&TruePrintDlgA, DetourPrintDlgA);
DetourDetach((PVOID *)&TruePrintDlgW, DetourPrintDlgW);
DetourDetach((PVOID *)&TruePrintDlgExA, DetourPrintDlgExA);
DetourDetach((PVOID *)&TruePrintDlgExW, DetourPrintDlgExW);
DetourTransactionCommit();}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
if (dwReason == DLL_PROCESS_ATTACH) {
BeginMyDetours();
}
else if (dwReason == DLL_PROCESS_DETACH) {
EndMyDetours();
}
return TRUE;
}VOID NullExport()
{
}