mirror of https://github.com/tongzx/nt5src
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
87 lines
1.6 KiB
/*++
|
|
|
|
Copyright (c) 2000 Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
ForceCoInitialize.cpp
|
|
|
|
Abstract:
|
|
|
|
Makes sure we call CoInitialize on this thread if nobody else has.
|
|
|
|
Notes:
|
|
|
|
This is a general purpose shim.
|
|
|
|
History:
|
|
|
|
02/22/2000 linstev Created
|
|
|
|
--*/
|
|
|
|
#include "precomp.h"
|
|
|
|
IMPLEMENT_SHIM_BEGIN(ForceCoInitialize)
|
|
#include "ShimHookMacro.h"
|
|
|
|
|
|
APIHOOK_ENUM_BEGIN
|
|
APIHOOK_ENUM_ENTRY(CoCreateInstance)
|
|
APIHOOK_ENUM_END
|
|
|
|
/*++
|
|
|
|
Call CoInitialize if nobody else has
|
|
|
|
--*/
|
|
|
|
STDAPI
|
|
APIHOOK(CoCreateInstance)(
|
|
REFCLSID rclsid,
|
|
LPUNKNOWN pUnkOuter,
|
|
DWORD dwClsContext,
|
|
REFIID riid,
|
|
LPVOID* ppv
|
|
)
|
|
{
|
|
HRESULT hr = ORIGINAL_API(CoCreateInstance)(
|
|
rclsid,
|
|
pUnkOuter,
|
|
dwClsContext,
|
|
riid,
|
|
ppv);
|
|
|
|
if (hr == CO_E_NOTINITIALIZED) {
|
|
if (CoInitialize(NULL) == S_OK) {
|
|
DPFN(
|
|
eDbgLevelInfo,
|
|
"[CoCreateInstance] Success: Initialized previously uninitialized COM.\n");
|
|
}
|
|
|
|
hr = ORIGINAL_API(CoCreateInstance)(
|
|
rclsid,
|
|
pUnkOuter,
|
|
dwClsContext,
|
|
riid,
|
|
ppv);
|
|
}
|
|
|
|
return hr;
|
|
}
|
|
|
|
/*++
|
|
|
|
Register hooked functions
|
|
|
|
--*/
|
|
|
|
HOOK_BEGIN
|
|
|
|
APIHOOK_ENTRY(OLE32.DLL, CoCreateInstance)
|
|
|
|
HOOK_END
|
|
|
|
|
|
IMPLEMENT_SHIM_END
|
|
|