Source code of Windows XP (NT5)
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.

87 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceCoInitialize.cpp
  5. Abstract:
  6. Makes sure we call CoInitialize on this thread if nobody else has.
  7. Notes:
  8. This is a general purpose shim.
  9. History:
  10. 02/22/2000 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(ForceCoInitialize)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(CoCreateInstance)
  17. APIHOOK_ENUM_END
  18. /*++
  19. Call CoInitialize if nobody else has
  20. --*/
  21. STDAPI
  22. APIHOOK(CoCreateInstance)(
  23. REFCLSID rclsid,
  24. LPUNKNOWN pUnkOuter,
  25. DWORD dwClsContext,
  26. REFIID riid,
  27. LPVOID* ppv
  28. )
  29. {
  30. HRESULT hr = ORIGINAL_API(CoCreateInstance)(
  31. rclsid,
  32. pUnkOuter,
  33. dwClsContext,
  34. riid,
  35. ppv);
  36. if (hr == CO_E_NOTINITIALIZED) {
  37. if (CoInitialize(NULL) == S_OK) {
  38. DPFN(
  39. eDbgLevelInfo,
  40. "[CoCreateInstance] Success: Initialized previously uninitialized COM.\n");
  41. }
  42. hr = ORIGINAL_API(CoCreateInstance)(
  43. rclsid,
  44. pUnkOuter,
  45. dwClsContext,
  46. riid,
  47. ppv);
  48. }
  49. return hr;
  50. }
  51. /*++
  52. Register hooked functions
  53. --*/
  54. HOOK_BEGIN
  55. APIHOOK_ENTRY(OLE32.DLL, CoCreateInstance)
  56. HOOK_END
  57. IMPLEMENT_SHIM_END