OpenPrinterAPI挂钩

时间:2012-05-10 08:06:24

标签: c++ visual-c++ dll

我正在使用OpenPrinter API,但它没有得到Hook,我的代码如下所示。 我无法挂钩此功能,请帮助我,如果某些参数(签名)不正确....

typedef BOOL (WINAPI *OpenPrinterANext)(__in_opt LPSTR pPrinterName,__out LPHANDLE  phPrinter,__in_opt LPPRINTER_DEFAULTSA pDefault);
OpenPrinterANext Real_OpenPrinterA = NULL;

typedef BOOL (WINAPI *OpenPrinterWNext)(__in_opt LPWSTR pPrinterName,__out LPHANDLE phPrinter,__in_opt LPPRINTER_DEFAULTSW pDefault);
OpenPrinterWNext Real_OpenPrinterW = NULL;


BOOL WINAPI OpenPrinterACallback(__in_opt LPSTR pPrinterName,__out LPHANDLE         phPrinter,__in_opt LPPRINTER_DEFAULTSA pDefault)
{
 MessageBoxA(NULL,"OpenPrinterA Function Called","Info",MB_OK);
 return Real_OpenPrinterA(pPrinterName,phPrinter, pDefault);
}

BOOL WINAPI OpenPrinterWCallback(__in_opt LPWSTR pPrinterName,__out LPHANDLE phPrinter,__in_opt LPPRINTER_DEFAULTSW pDefault)
{
 MessageBoxA(NULL,"OpenPrinterW Function Called","Info",MB_OK);
 return Real_OpenPrinterW(pPrinterName,phPrinter, pDefault);
}
 BOOL APIENTRY DllMain( HMODULE hModule,
                   DWORD  ul_reason_for_call,
                   LPVOID lpReserved
                 )
{

switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
                        if (MH_Initialize() != MH_OK)
                        {
                            MessageBoxW(NULL,L"Failed Initialize",L"Info!",MB_ICONWARNING|MB_OK);   
                        }            
                        if 
                        if (MH_CreateHook(&OpenPrinterA, &OpenPrinterACallback, reinterpret_cast<void**>(&Real_OpenPrinterA)) != MH_OK)
                        {
                            MessageBoxW(NULL,L"Printing Disabled by hooking",L"Info!",MB_ICONWARNING|MB_OK);
                        }
                        if (MH_EnableHook(&OpenPrinterA) != MH_OK)
                        {
                            MessageBoxW(NULL,L"Failed EnableHook Printing",L"Info!",MB_ICONWARNING|MB_OK);
                        }
                        if (MH_CreateHook(&OpenPrinterW, &OpenPrinterWCallback, reinterpret_cast<void**>(&Real_OpenPrinterW)) != MH_OK)
                        {
                            MessageBoxW(NULL,L"Printing Disabled by hooking",L"Info!",MB_ICONWARNING|MB_OK);
                        }
                        if (MH_EnableHook(&OpenPrinterW) != MH_OK)
                        {
                            MessageBoxW(NULL,L"Failed EnableHook Printing",L"Info!",MB_ICONWARNING|MB_OK);
                        }
break ;

case DLL_PROCESS_DETACH:
                       if (MH_DisableHook(&OpenPrinterA) != MH_OK)
                       {

                       }
                       if (MH_DisableHook(&OpenPrinterW) != MH_OK)
                       {

                       }
                       if (MH_Uninitialize() != MH_OK)
                       {

                       }
                       break;
}

return TRUE;
}  

请帮助我任何一个人 在此先感谢

0 个答案:

没有答案