title: What could possibly cause ShellExecute to return SE_ERR_OOM (error 8)?
body: <p>I frequently call ShellExecute from a native C++/Win32 application to execute any shell item selected by the end-user from the GUI. Items are either executable files/scripts or links (.lnk). In some conditions that remain obscure to me, the following function sometimes returns <code>8</code> (<code>SE_ERR_OOM</code> error; only very briefly documented). As a result, the item is not executed. What could possibly cause this error?</p>
  
  <pre><code>int doExecute(LPCTSTR file, LPCTSTR args, LPCTSTR workDir)
  {
      assert(file &amp;&amp; *file);
      HRESULT hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
      assert(hRes == S_OK || hRes == S_FALSE);
      int code = (int)ShellExecute(NULL, NULL, file, args, workDir, SW_SHOWNORMAL);
      doLog("ShellExecute returned: %d, %u", code, GetLastError()); // EDIT
      CoUninitialize();
      return code;
  }
  </code></pre>
  
  <p>The context:</p>
  
  <ul>
  <li>Windows8 64bit, application is 32bit, could not try on any other machine</li>
  <li>Application is multi-threaded</li>
  <li>By design, a new thread is always created specifically to do this call</li>
  <li>The assertions in this code never break during my debug sessions</li>
  <li>The application itself does not make direct use of COM but may have to call Win32 APIs that indirectly use it since it interacts quite frequently with the shell. In these cases, COM is always initialized with the same flags than shown above.</li>
  <li>The flags passed to <code>CoInitializeEx</code> have been blindly chosen after MSDN recommendation (see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153.aspx" rel="nofollow">ShellExecute</a> documentation), not because of a personal choice</li>
  </ul>
  
  <p>Observations about the bug so far:</p>
  
  <ul>
  <li>It's rare</li>
  <li>It occurred only after one or several hibernations (my application is always running on my laptop and I use it quite often)</li>
  <li>An immediate call to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679360.aspx" rel="nofollow">GetLastError</a> after calling <code>ShellExecute</code> always returned <code>0</code></li>
  <li>As far as I can remember, it always happened while trying to execute a <code>.lnk</code> file, but not always the same file</li>
  <li>A quick look at <code>Process Explorer</code> (sysinternals.com) running on the machine does not show any peak of use of memory</li>
  <li><strong>edit</strong>: I made a last test before posting here by calling <code>doExecute</code> 200 times in a row. All processes were spawned without error.</li>
  </ul>