Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.0 KiB

  1. #include "stock.h"
  2. #pragma hdrstop
  3. // Need to put into separate file because for some reason the /Gy compiler
  4. // option doesn't work.
  5. //
  6. // COM Initialization is weird due to multithreaded apartments.
  7. //
  8. // If this thread has not called CoInitialize yet, but some other thread
  9. // in the process has called CoInitialize with the COINIT_MULTITHREADED,
  10. // then that infects our thread with the multithreaded virus, and a
  11. // COINIT_APARTMENTTHREADED will fail.
  12. //
  13. // In this case, we must turn around and re-init ourselves as
  14. // COINIT_MULTITHREADED to increment the COM refcount on our thread.
  15. // If we didn't do that, and that other thread decided to do a
  16. // CoUninitialize, that >secretly< uninitializes COM on our own thread
  17. // and we fall over and die.
  18. //
  19. STDAPI SHCoInitialize(void)
  20. {
  21. HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
  22. if (FAILED(hr))
  23. {
  24. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
  25. }
  26. return hr;
  27. }