title: CAPIHook forcibly hooks ::LoadLibrary from QT dll
body: <p>I use QT 4.8.6, MSVC 2013. We use API hook to intercept exceptions:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  ...
  ...
  #ifdef _WIN32 
    CAPIHook apiHook("kernel32.dll",  "SetUnhandledExceptionFilter",(PROC)RedirectedSetUnhandledExceptionFilter);
  #endif
  ...
  }
  </code></pre>
  
  <p>But, does anybody can explain me why  ::LoadLibrary call from QT redirected to HMODULE WINAPI CAPIHook::LoadLibraryW2(PCWSTR pszModulePath)?</p>
  
  <p>From there:</p>
  
  <pre><code>for (int i = 0; i &lt; searchOrder.count(); ++i) {
      QString fullPathAttempt = searchOrder.at(i);
      if (!fullPathAttempt.endsWith(QLatin1Char('\\')))
          fullPathAttempt.append(QLatin1Char('\\'));
      fullPathAttempt.append(fileName);
      HINSTANCE inst = ::LoadLibrary((const wchar_t *)fullPathAttempt.utf16());
      if (inst != 0)
          return inst;
  }
  </code></pre>
  
  <p>Where fullPathAttempt is "C:\Windows\system32\shell32.dll"   </p>
  
  <p>To here:</p>
  
  <pre><code>HMODULE WINAPI CAPIHook::LoadLibraryW2(PCWSTR pszModulePath) {
     HMODULE hmod = ::LoadLibraryW(pszModulePath);
     FixupNewlyLoadedModule(hmod, 0);
     return(hmod);
  </code></pre>
  
  <p>}</p>
  
  <p>Full call stack:
  <a href="http://i.stack.imgur.com/BqpCI.png" rel="nofollow">Call Stack</a></p>
  
  <p>This is very expensive redirect in some cases. 
  How to avoid this behaviour? </p>