印刷ダイアログをスキップする

Windows XPで印刷ダイアログ表示させずに 印刷を実行させる方法をおしえてください。 通常アプリケーションからプリントを実行すると (たとえば IE6で メニュー ファイル .. - 人力検索はてな


Detoursでcomdlg32.dllをフックしてみた。動く動く。


#include
#include

static 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()
{
}