列宁大哥,小弟是个新手,以前一直用d7,最近刚搞vc++ 。 用的是2010 。 我想hook print 的一组api
CreateDCA,CreateDCW,StartDocA,StartDocW,StartDocPrinterW,EndDoc,StartPage,
StartPagePrinter,WritePrinter,DeleteEnhMetaFile,EndPage,EndPagePrinter,EndDocPrinter不知道为什么没有成功,望不吝赐教。下面是部分代码:
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pStartDocA, StartDocA);
DetourAttach(&(PVOID&)pStartDocW, StartDocW);
DetourAttach(&(PVOID&)pStartDocPrinterW, StartDocPrinterW);
DetourAttach(&(PVOID&)pEndDoc, EndDoc);
DetourAttach(&(PVOID&)pStartPage, StartPage);
DetourAttach(&(PVOID&)pStartPagePrinter, StartPagePrinter);
DetourAttach(&(PVOID&)pWritePrinter, WritePrinter);
DetourAttach(&(PVOID&)pDeleteEnhMetaFile, DeleteEnhMetaFile);
DetourAttach(&(PVOID&)pEndPage, EndPage);
DetourAttach(&(PVOID&)pEndPagePrinter, EndPagePrinter);
DetourAttach(&(PVOID&)pEndDocPrinter, EndDocPrinter);
DetourTransactionCommit();
break; case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pStartDocA, MyStartDocA);
DetourDetach(&(PVOID&)pStartDocW, MyStartDocW);
DetourDetach(&(PVOID&)pStartDocPrinterW, MyStartDocPrinterW);
DetourDetach(&(PVOID&)pEndDoc, MyEndDoc);
DetourDetach(&(PVOID&)pStartPage, MyStartPage);
DetourDetach(&(PVOID&)pStartPagePrinter, MyStartPagePrinter);
DetourDetach(&(PVOID&)pWritePrinter, MyWritePrinter);
DetourDetach(&(PVOID&)pDeleteEnhMetaFile, MyDeleteEnhMetaFile);
DetourDetach(&(PVOID&)pEndPage, MyEndPage);
DetourDetach(&(PVOID&)pEndPagePrinter, MyEndPagePrinter);
DetourDetach(&(PVOID&)pEndDocPrinter, MyEndDocPrinter);
DetourTransactionCommit(); break;
}
LRESULT __declspec(dllexport) CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(m_ghHook, nCode, wParam, lParam);
}
BOOL WINAPI StartHook(void)
{
m_ghHook = SetWindowsHookEx(WH_CBT, CBTProc, m_ghInstance, NULL);
if(NULL != m_ghHook)
{
return TRUE;
}
else
return FALSE;
}BOOL WINAPI StopHook(void)
{
return UnhookWindowsHookEx(m_ghHook);
}//
int WINAPI MyStartDocA(HDC hdc, CONST DOCINFOA* lpdi){ int nJobID = pStartDocA(hdc, (DOCINFOA*)lpdi);
return nJobID;
}
CreateDCA,CreateDCW,StartDocA,StartDocW,StartDocPrinterW,EndDoc,StartPage,
StartPagePrinter,WritePrinter,DeleteEnhMetaFile,EndPage,EndPagePrinter,EndDocPrinter不知道为什么没有成功,望不吝赐教。下面是部分代码:
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pStartDocA, StartDocA);
DetourAttach(&(PVOID&)pStartDocW, StartDocW);
DetourAttach(&(PVOID&)pStartDocPrinterW, StartDocPrinterW);
DetourAttach(&(PVOID&)pEndDoc, EndDoc);
DetourAttach(&(PVOID&)pStartPage, StartPage);
DetourAttach(&(PVOID&)pStartPagePrinter, StartPagePrinter);
DetourAttach(&(PVOID&)pWritePrinter, WritePrinter);
DetourAttach(&(PVOID&)pDeleteEnhMetaFile, DeleteEnhMetaFile);
DetourAttach(&(PVOID&)pEndPage, EndPage);
DetourAttach(&(PVOID&)pEndPagePrinter, EndPagePrinter);
DetourAttach(&(PVOID&)pEndDocPrinter, EndDocPrinter);
DetourTransactionCommit();
break; case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pStartDocA, MyStartDocA);
DetourDetach(&(PVOID&)pStartDocW, MyStartDocW);
DetourDetach(&(PVOID&)pStartDocPrinterW, MyStartDocPrinterW);
DetourDetach(&(PVOID&)pEndDoc, MyEndDoc);
DetourDetach(&(PVOID&)pStartPage, MyStartPage);
DetourDetach(&(PVOID&)pStartPagePrinter, MyStartPagePrinter);
DetourDetach(&(PVOID&)pWritePrinter, MyWritePrinter);
DetourDetach(&(PVOID&)pDeleteEnhMetaFile, MyDeleteEnhMetaFile);
DetourDetach(&(PVOID&)pEndPage, MyEndPage);
DetourDetach(&(PVOID&)pEndPagePrinter, MyEndPagePrinter);
DetourDetach(&(PVOID&)pEndDocPrinter, MyEndDocPrinter);
DetourTransactionCommit(); break;
}
LRESULT __declspec(dllexport) CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(m_ghHook, nCode, wParam, lParam);
}
BOOL WINAPI StartHook(void)
{
m_ghHook = SetWindowsHookEx(WH_CBT, CBTProc, m_ghInstance, NULL);
if(NULL != m_ghHook)
{
return TRUE;
}
else
return FALSE;
}BOOL WINAPI StopHook(void)
{
return UnhookWindowsHookEx(m_ghHook);
}//
int WINAPI MyStartDocA(HDC hdc, CONST DOCINFOA* lpdi){ int nJobID = pStartDocA(hdc, (DOCINFOA*)lpdi);
return nJobID;
}
DetourAttach,DetourDetach, 好像不是注入,是用的改引入表方式。 是这样的吗?
在StartHook启动后,不会强制影射到其他进程中去吗?
StartDocA StartDocW StartDocPrinterW EndDoc StartPage StartPagePrinter WritePrinter DeleteEnhMetaFile EndPage EndPagePrinter EndDocPrinter 当我把dll注入到比如notepad++中,我启动打印。应该vs2010 能调试到我的函数。 是不是我本身的dll,没有消息循环。要用notepad++ 的消息循环, 然后我用钩子,勾住它。
这样写钩子对吗?LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(m_ghHook, nCode, wParam, lParam);
}BOOL WINAPI StartHook(void)
{
m_ghHook = SetWindowsHookEx(WH_CALLWNDPROC, CBTProc, m_ghInstance, NULL);
if(NULL != m_ghHook)
{
return TRUE;
}
else
return FALSE;
}
然后去msdn看有哪些打印api没有处理