title: OpenPrinterAPI Hooking
body: <p>I am Hooking to OpenPrinter API but it is not getting Hook , my code is as below. 
  i am not able to hook this function please help me if some parameters(signature) are not correct.... </p>
  
  <pre class="lang-cpp prettyprint-override"><code>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(&amp;OpenPrinterA, &amp;OpenPrinterACallback, reinterpret_cast&lt;void**&gt;(&amp;Real_OpenPrinterA)) != MH_OK)
                          {
                              MessageBoxW(NULL,L"Printing Disabled by hooking",L"Info!",MB_ICONWARNING|MB_OK);
                          }
                          if (MH_EnableHook(&amp;OpenPrinterA) != MH_OK)
                          {
                              MessageBoxW(NULL,L"Failed EnableHook Printing",L"Info!",MB_ICONWARNING|MB_OK);
                          }
                          if (MH_CreateHook(&amp;OpenPrinterW, &amp;OpenPrinterWCallback, reinterpret_cast&lt;void**&gt;(&amp;Real_OpenPrinterW)) != MH_OK)
                          {
                              MessageBoxW(NULL,L"Printing Disabled by hooking",L"Info!",MB_ICONWARNING|MB_OK);
                          }
                          if (MH_EnableHook(&amp;OpenPrinterW) != MH_OK)
                          {
                              MessageBoxW(NULL,L"Failed EnableHook Printing",L"Info!",MB_ICONWARNING|MB_OK);
                          }
  break ;
  
  case DLL_PROCESS_DETACH:
                         if (MH_DisableHook(&amp;OpenPrinterA) != MH_OK)
                         {
  
                         }
                         if (MH_DisableHook(&amp;OpenPrinterW) != MH_OK)
                         {
  
                         }
                         if (MH_Uninitialize() != MH_OK)
                         {
  
                         }
                         break;
  }
  
  return TRUE;
  }  
  </code></pre>
  
  <p>Please Help me any one<br>
  Thanks in Advance</p>