2009-10-20 12:26:51 +00:00
|
|
|
/*
|
|
|
|
* ReactOS ATL
|
|
|
|
*
|
|
|
|
* Copyright 2009 Andrew Hill <ash77@reactos.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-10-27 10:34:16 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-10-20 12:26:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-02-26 11:43:19 +00:00
|
|
|
#pragma once
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2019-04-05 21:22:55 +00:00
|
|
|
#include "atldef.h"
|
2009-10-20 12:26:51 +00:00
|
|
|
#include "atlcore.h"
|
|
|
|
#include "statreg.h"
|
2016-02-23 19:31:38 +00:00
|
|
|
#include "atlcomcli.h"
|
2016-03-17 18:05:44 +00:00
|
|
|
#include "atlalloc.h"
|
2019-04-05 21:22:55 +00:00
|
|
|
#include "atlexcept.h"
|
2022-01-22 15:59:12 +00:00
|
|
|
#include "atltrace.h"
|
2016-04-10 16:53:00 +00:00
|
|
|
#include "comcat.h"
|
2016-08-10 19:34:38 +00:00
|
|
|
#include "tchar.h"
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// It is common to use this in ATL constructors. They only store this for later use, so the usage is safe.
|
|
|
|
#pragma warning(disable:4355)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ATLTRY
|
|
|
|
#define ATLTRY(x) x;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _ATL_DISABLE_NO_VTABLE
|
|
|
|
#define ATL_NO_VTABLE
|
|
|
|
#else
|
|
|
|
#define ATL_NO_VTABLE __declspec(novtable)
|
|
|
|
#endif
|
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
#ifndef ATL_DEPRECATED
|
|
|
|
#define ATL_DEPRECATED __declspec(deprecated)
|
|
|
|
#endif
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
namespace ATL
|
|
|
|
{
|
|
|
|
|
|
|
|
class CAtlModule;
|
|
|
|
class CComModule;
|
|
|
|
class CAtlComModule;
|
2015-05-03 15:10:09 +00:00
|
|
|
__declspec(selectany) CAtlModule *_pAtlModule = NULL;
|
|
|
|
__declspec(selectany) CComModule *_pModule = NULL;
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2023-04-15 20:21:33 +00:00
|
|
|
template <bool isDll, typename T> struct CAtlValidateModuleConfiguration
|
|
|
|
{
|
|
|
|
#if !defined(_WINDLL) && !defined(_USRDLL)
|
|
|
|
static_assert(!isDll, "_WINDLL or _USRDLL must be defined when 'CAtlDllModuleT<T>' is used");
|
|
|
|
#else
|
|
|
|
static_assert(isDll, "_WINDLL or _USRDLL must be defined when 'CAtlExeModuleT<T>' is used");
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-04-10 16:53:00 +00:00
|
|
|
|
|
|
|
struct _ATL_CATMAP_ENTRY
|
|
|
|
{
|
|
|
|
int iType;
|
|
|
|
const GUID* pcatid;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define _ATL_CATMAP_ENTRY_END 0
|
|
|
|
#define _ATL_CATMAP_ENTRY_IMPLEMENTED 1
|
|
|
|
#define _ATL_CATMAP_ENTRY_REQUIRED 2
|
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
typedef HRESULT (WINAPI _ATL_CREATORFUNC)(void *pv, REFIID riid, LPVOID *ppv);
|
|
|
|
typedef LPCTSTR (WINAPI _ATL_DESCRIPTIONFUNC)();
|
|
|
|
typedef const struct _ATL_CATMAP_ENTRY * (_ATL_CATMAPFUNC)();
|
|
|
|
|
|
|
|
struct _ATL_OBJMAP_ENTRY30
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
const CLSID *pclsid;
|
|
|
|
HRESULT (WINAPI *pfnUpdateRegistry)(BOOL bRegister);
|
|
|
|
_ATL_CREATORFUNC *pfnGetClassObject;
|
|
|
|
_ATL_CREATORFUNC *pfnCreateInstance;
|
|
|
|
IUnknown *pCF;
|
|
|
|
DWORD dwRegister;
|
|
|
|
_ATL_DESCRIPTIONFUNC *pfnGetObjectDescription;
|
|
|
|
_ATL_CATMAPFUNC *pfnGetCategoryMap;
|
|
|
|
void (WINAPI *pfnObjectMain)(bool bStarting);
|
|
|
|
|
|
|
|
HRESULT WINAPI RevokeClassObject()
|
|
|
|
{
|
|
|
|
if (dwRegister == 0)
|
|
|
|
return S_OK;
|
|
|
|
return CoRevokeClassObject(dwRegister);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI RegisterClassObject(DWORD dwClsContext, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
IUnknown *p;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
p = NULL;
|
|
|
|
if (pfnGetClassObject == NULL)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
hResult = pfnGetClassObject(reinterpret_cast<LPVOID *>(pfnCreateInstance), IID_IUnknown, reinterpret_cast<LPVOID *>(&p));
|
|
|
|
if (SUCCEEDED(hResult))
|
|
|
|
hResult = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &dwRegister);
|
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
p->Release();
|
|
|
|
|
|
|
|
return hResult;
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef _ATL_OBJMAP_ENTRY30 _ATL_OBJMAP_ENTRY;
|
|
|
|
|
|
|
|
typedef void (__stdcall _ATL_TERMFUNC)(DWORD_PTR dw);
|
|
|
|
|
|
|
|
struct _ATL_TERMFUNC_ELEM
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
_ATL_TERMFUNC *pFunc;
|
|
|
|
DWORD_PTR dw;
|
|
|
|
_ATL_TERMFUNC_ELEM *pNext;
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _ATL_MODULE70
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
UINT cbSize;
|
|
|
|
LONG m_nLockCnt;
|
|
|
|
_ATL_TERMFUNC_ELEM *m_pTermFuncs;
|
|
|
|
CComCriticalSection m_csStaticDataInitAndTypeInfo;
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
typedef _ATL_MODULE70 _ATL_MODULE;
|
|
|
|
|
|
|
|
typedef HRESULT (WINAPI _ATL_CREATORARGFUNC)(void *pv, REFIID riid, LPVOID *ppv, DWORD_PTR dw);
|
|
|
|
|
|
|
|
#define _ATL_SIMPLEMAPENTRY ((ATL::_ATL_CREATORARGFUNC *)1)
|
|
|
|
|
|
|
|
struct _ATL_INTMAP_ENTRY
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
const IID *piid;
|
|
|
|
DWORD_PTR dw;
|
|
|
|
_ATL_CREATORARGFUNC *pFunc;
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _AtlCreateWndData
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
void *m_pThis;
|
|
|
|
DWORD m_dwThreadID;
|
|
|
|
_AtlCreateWndData *m_pNext;
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _ATL_COM_MODULE70
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
UINT cbSize;
|
|
|
|
HINSTANCE m_hInstTypeLib;
|
|
|
|
_ATL_OBJMAP_ENTRY **m_ppAutoObjMapFirst;
|
|
|
|
_ATL_OBJMAP_ENTRY **m_ppAutoObjMapLast;
|
|
|
|
CComCriticalSection m_csObjMap;
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
typedef _ATL_COM_MODULE70 _ATL_COM_MODULE;
|
|
|
|
|
|
|
|
struct _ATL_WIN_MODULE70
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
UINT cbSize;
|
|
|
|
CComCriticalSection m_csWindowCreate;
|
|
|
|
_AtlCreateWndData *m_pCreateWndList;
|
2009-10-20 12:26:51 +00:00
|
|
|
#ifdef NOTYET
|
2015-05-03 15:10:09 +00:00
|
|
|
CSimpleArray<ATOM> m_rgWindowClassAtoms;
|
2009-10-20 12:26:51 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
typedef _ATL_WIN_MODULE70 _ATL_WIN_MODULE;
|
|
|
|
|
2023-04-15 20:21:33 +00:00
|
|
|
|
|
|
|
// Auto object map
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma section("ATL$__a", read, write)
|
|
|
|
#pragma section("ATL$__z", read, write)
|
|
|
|
#pragma section("ATL$__m", read, write)
|
|
|
|
#define _ATLALLOC(x) __declspec(allocate(x))
|
|
|
|
|
|
|
|
#if defined(_M_IX86)
|
|
|
|
#define OBJECT_ENTRY_PRAGMA(class) __pragma(comment(linker, "/include:___pobjMap_" #class));
|
|
|
|
#elif defined(_M_IA64) || defined(_M_AMD64) || (_M_ARM) || defined(_M_ARM64)
|
|
|
|
#define OBJECT_ENTRY_PRAGMA(class) __pragma(comment(linker, "/include:__pobjMap_" #class));
|
|
|
|
#else
|
|
|
|
#error Your platform is not supported.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
|
|
|
|
// GCC completely ignores __attribute__((unused)) on the __pobjMap_ pointer, so we pass it to a function that is not allowed to be optimized....
|
|
|
|
static int __attribute__((optimize("O0"), unused)) hack_for_gcc(const _ATL_OBJMAP_ENTRY * const *)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _ATLALLOC(x) __attribute__((section(x)))
|
|
|
|
#define OBJECT_ENTRY_PRAGMA(class) static int __pobjMap_hack_##class = hack_for_gcc(&__pobjMap_##class);
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error Your compiler is not supported.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
__declspec(selectany) _ATLALLOC("ATL$__a") _ATL_OBJMAP_ENTRY *__pobjMapEntryFirst = NULL;
|
|
|
|
__declspec(selectany) _ATLALLOC("ATL$__z") _ATL_OBJMAP_ENTRY *__pobjMapEntryLast = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
struct _ATL_REGMAP_ENTRY
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
LPCOLESTR szKey;
|
|
|
|
LPCOLESTR szData;
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
2017-10-22 20:25:03 +00:00
|
|
|
HRESULT WINAPI AtlWinModuleInit(_ATL_WIN_MODULE *pWinModule);
|
|
|
|
HRESULT WINAPI AtlWinModuleTerm(_ATL_WIN_MODULE *pWinModule, HINSTANCE hInst);
|
|
|
|
HRESULT WINAPI AtlInternalQueryInterface(void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject);
|
|
|
|
void WINAPI AtlWinModuleAddCreateWndData(_ATL_WIN_MODULE *pWinModule, _AtlCreateWndData *pData, void *pObject);
|
|
|
|
void *WINAPI AtlWinModuleExtractCreateWndData(_ATL_WIN_MODULE *pWinModule);
|
|
|
|
HRESULT WINAPI AtlComModuleGetClassObject(_ATL_COM_MODULE *pComModule, REFCLSID rclsid, REFIID riid, LPVOID *ppv);
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2017-10-22 20:25:03 +00:00
|
|
|
HRESULT WINAPI AtlComModuleRegisterServer(_ATL_COM_MODULE *mod, BOOL bRegTypeLib, const CLSID *clsid);
|
|
|
|
HRESULT WINAPI AtlComModuleUnregisterServer(_ATL_COM_MODULE *mod, BOOL bRegTypeLib, const CLSID *clsid);
|
|
|
|
|
|
|
|
HRESULT WINAPI AtlComModuleRegisterClassObjects(_ATL_COM_MODULE *module, DWORD context, DWORD flags);
|
|
|
|
HRESULT WINAPI AtlComModuleRevokeClassObjects(_ATL_COM_MODULE *module);
|
2016-04-10 16:53:00 +00:00
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
template<class TLock>
|
|
|
|
class CComCritSecLock
|
|
|
|
{
|
|
|
|
private:
|
2015-05-03 15:10:09 +00:00
|
|
|
bool m_bLocked;
|
|
|
|
TLock &m_cs;
|
2009-10-20 12:26:51 +00:00
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
CComCritSecLock(TLock &cs, bool bInitialLock = true) : m_cs(cs)
|
|
|
|
{
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
m_bLocked = false;
|
|
|
|
if (bInitialLock)
|
|
|
|
{
|
|
|
|
hResult = Lock();
|
|
|
|
if (FAILED(hResult))
|
|
|
|
{
|
|
|
|
ATLASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~CComCritSecLock()
|
|
|
|
{
|
|
|
|
if (m_bLocked)
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT Lock()
|
|
|
|
{
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
ATLASSERT(!m_bLocked);
|
|
|
|
hResult = m_cs.Lock();
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
m_bLocked = true;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Unlock()
|
|
|
|
{
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
ATLASSERT(m_bLocked);
|
|
|
|
hResult = m_cs.Unlock();
|
|
|
|
if (FAILED(hResult))
|
|
|
|
{
|
|
|
|
ATLASSERT(false);
|
|
|
|
}
|
|
|
|
m_bLocked = false;
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
2015-11-30 12:07:18 +00:00
|
|
|
|
|
|
|
class CHandle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HANDLE m_handle;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CHandle() :
|
|
|
|
m_handle(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CHandle(_Inout_ CHandle& handle) :
|
|
|
|
m_handle(NULL)
|
|
|
|
{
|
|
|
|
Attach(handle.Detach());
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit CHandle(_In_ HANDLE handle) :
|
|
|
|
m_handle(handle)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~CHandle()
|
|
|
|
{
|
|
|
|
if (m_handle)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHandle& operator=(_Inout_ CHandle& handle)
|
|
|
|
{
|
|
|
|
if (this != &handle)
|
|
|
|
{
|
|
|
|
if (m_handle)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
Attach(handle.Detach());
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HANDLE() const
|
|
|
|
{
|
|
|
|
return m_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Attach(_In_ HANDLE handle)
|
|
|
|
{
|
|
|
|
ATLASSERT(m_handle == NULL);
|
|
|
|
m_handle = handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE Detach()
|
|
|
|
{
|
|
|
|
HANDLE handle = m_handle;
|
|
|
|
m_handle = NULL;
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close()
|
|
|
|
{
|
|
|
|
if (m_handle)
|
|
|
|
{
|
|
|
|
::CloseHandle(m_handle);
|
|
|
|
m_handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
inline BOOL WINAPI InlineIsEqualUnknown(REFGUID rguid1)
|
|
|
|
{
|
|
|
|
return (
|
2015-05-03 15:10:09 +00:00
|
|
|
((unsigned long *)&rguid1)[0] == 0 &&
|
|
|
|
((unsigned long *)&rguid1)[1] == 0 &&
|
|
|
|
((unsigned long *)&rguid1)[2] == 0x000000C0 &&
|
|
|
|
((unsigned long *)&rguid1)[3] == 0x46000000);
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class CComMultiThreadModelNoCS
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
typedef CComFakeCriticalSection AutoCriticalSection;
|
|
|
|
typedef CComFakeCriticalSection CriticalSection;
|
|
|
|
typedef CComMultiThreadModelNoCS ThreadModelNoCS;
|
|
|
|
typedef CComFakeCriticalSection AutoDeleteCriticalSection;
|
|
|
|
|
|
|
|
static ULONG WINAPI Increment(LPLONG p)
|
|
|
|
{
|
|
|
|
return InterlockedIncrement(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Decrement(LPLONG p)
|
|
|
|
{
|
|
|
|
return InterlockedDecrement(p);
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CComMultiThreadModel
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
typedef CComAutoCriticalSection AutoCriticalSection;
|
|
|
|
typedef CComCriticalSection CriticalSection;
|
|
|
|
typedef CComMultiThreadModelNoCS ThreadModelNoCS;
|
|
|
|
typedef CComAutoDeleteCriticalSection AutoDeleteCriticalSection;
|
|
|
|
|
|
|
|
static ULONG WINAPI Increment(LPLONG p)
|
|
|
|
{
|
|
|
|
return InterlockedIncrement(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Decrement(LPLONG p)
|
|
|
|
{
|
|
|
|
return InterlockedDecrement(p);
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CComSingleThreadModel
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
typedef CComFakeCriticalSection AutoCriticalSection;
|
|
|
|
typedef CComFakeCriticalSection CriticalSection;
|
|
|
|
typedef CComSingleThreadModel ThreadModelNoCS;
|
|
|
|
typedef CComFakeCriticalSection AutoDeleteCriticalSection;
|
|
|
|
|
|
|
|
static ULONG WINAPI Increment(LPLONG p)
|
|
|
|
{
|
|
|
|
return ++*p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Decrement(LPLONG p)
|
|
|
|
{
|
|
|
|
return --*p;
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(_ATL_FREE_THREADED)
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
typedef CComMultiThreadModel CComObjectThreadModel;
|
|
|
|
typedef CComMultiThreadModel CComGlobalsThreadModel;
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
#elif defined(_ATL_APARTMENT_THREADED)
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
typedef CComSingleThreadModel CComObjectThreadModel;
|
|
|
|
typedef CComMultiThreadModel CComGlobalsThreadModel;
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
#elif defined(_ATL_SINGLE_THREADED)
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
typedef CComSingleThreadModel CComObjectThreadModel;
|
|
|
|
typedef CComSingleThreadModel CComGlobalsThreadModel;
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error No threading model
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class CAtlModule : public _ATL_MODULE
|
|
|
|
{
|
|
|
|
public:
|
2016-04-08 08:38:48 +00:00
|
|
|
static GUID m_libid;
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
CAtlModule()
|
|
|
|
{
|
|
|
|
ATLASSERT(_pAtlModule == NULL);
|
|
|
|
_pAtlModule = this;
|
|
|
|
cbSize = sizeof(_ATL_MODULE);
|
|
|
|
m_nLockCnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual LONG GetLockCount()
|
|
|
|
{
|
|
|
|
return m_nLockCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual LONG Lock()
|
|
|
|
{
|
|
|
|
return CComGlobalsThreadModel::Increment(&m_nLockCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual LONG Unlock()
|
|
|
|
{
|
|
|
|
return CComGlobalsThreadModel::Decrement(&m_nLockCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* /*pRegistrar*/) = 0;
|
|
|
|
|
|
|
|
HRESULT WINAPI UpdateRegistryFromResource(LPCTSTR lpszRes, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries = NULL)
|
|
|
|
{
|
|
|
|
CRegObject registrar;
|
2015-06-20 09:22:55 +00:00
|
|
|
WCHAR modulePath[MAX_PATH];
|
2015-05-03 15:10:09 +00:00
|
|
|
HRESULT hResult;
|
2015-06-20 09:22:55 +00:00
|
|
|
PCWSTR lpwszRes;
|
2015-05-03 15:10:09 +00:00
|
|
|
|
|
|
|
hResult = CommonInitRegistrar(registrar, modulePath, sizeof(modulePath) / sizeof(modulePath[0]), pMapEntries);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
2015-06-20 09:22:55 +00:00
|
|
|
#ifdef UNICODE
|
|
|
|
lpwszRes = lpszRes;
|
|
|
|
#else
|
|
|
|
/* FIXME: this is a bit of a hack, need to re-evaluate */
|
|
|
|
WCHAR resid[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszRes, -1, resid, MAX_PATH);
|
|
|
|
lpwszRes = resid;
|
|
|
|
#endif
|
2015-05-03 15:10:09 +00:00
|
|
|
if (bRegister != FALSE)
|
2015-06-20 09:22:55 +00:00
|
|
|
hResult = registrar.ResourceRegisterSz(modulePath, lpwszRes, L"REGISTRY");
|
2015-05-03 15:10:09 +00:00
|
|
|
else
|
2015-06-20 09:22:55 +00:00
|
|
|
hResult = registrar.ResourceUnregisterSz(modulePath, lpwszRes, L"REGISTRY");
|
2015-05-03 15:10:09 +00:00
|
|
|
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI UpdateRegistryFromResource(UINT nResID, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries = NULL)
|
|
|
|
{
|
|
|
|
CRegObject registrar;
|
2015-06-20 09:22:55 +00:00
|
|
|
WCHAR modulePath[MAX_PATH];
|
2015-05-03 15:10:09 +00:00
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
hResult = CommonInitRegistrar(registrar, modulePath, sizeof(modulePath) / sizeof(modulePath[0]), pMapEntries);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
if (bRegister != FALSE)
|
2015-06-20 09:22:55 +00:00
|
|
|
hResult = registrar.ResourceRegister(modulePath, nResID, L"REGISTRY");
|
2015-05-03 15:10:09 +00:00
|
|
|
else
|
2015-06-20 09:22:55 +00:00
|
|
|
hResult = registrar.ResourceUnregister(modulePath, nResID, L"REGISTRY");
|
2015-05-03 15:10:09 +00:00
|
|
|
|
|
|
|
return hResult;
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
private:
|
2015-06-20 09:22:55 +00:00
|
|
|
HRESULT CommonInitRegistrar(CRegObject ®istrar, WCHAR *modulePath, DWORD modulePathCount, struct _ATL_REGMAP_ENTRY *pMapEntries)
|
2015-05-03 15:10:09 +00:00
|
|
|
{
|
|
|
|
HINSTANCE hInstance;
|
|
|
|
DWORD dwFLen;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
hInstance = _AtlBaseModule.GetModuleInstance();
|
2015-06-20 09:22:55 +00:00
|
|
|
dwFLen = GetModuleFileNameW(hInstance, modulePath, modulePathCount);
|
2015-05-03 15:10:09 +00:00
|
|
|
if (dwFLen == modulePathCount)
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
else if (dwFLen == 0)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
if (pMapEntries != NULL)
|
|
|
|
{
|
|
|
|
while (pMapEntries->szKey != NULL)
|
|
|
|
{
|
|
|
|
ATLASSERT(pMapEntries->szData != NULL);
|
|
|
|
hResult = registrar.AddReplacement(pMapEntries->szKey, pMapEntries->szData);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
pMapEntries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hResult = AddCommonRGSReplacements(®istrar);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
2015-06-20 09:22:55 +00:00
|
|
|
hResult = registrar.AddReplacement(L"Module", modulePath);
|
2015-05-03 15:10:09 +00:00
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
2015-06-20 09:22:55 +00:00
|
|
|
hResult = registrar.AddReplacement(L"Module_Raw", modulePath);
|
2015-05-03 15:10:09 +00:00
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
__declspec(selectany) GUID CAtlModule::m_libid = {0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} };
|
[browseui, shell32, explorer_new, include]
- Convert browseui to C++/ATL. As part of this, classes in browseui and now registered with .rgs files.
- Add AddressBand, AddressEditBox, BandProxy, BaseBar, BaseBarSite, BrandBand, InternetToolbar, ShellBrowser, ToolsBand, and TravelLog.
- Add stub implementations of commonbrowser, globalfoldersettings, and regtreeoptions.
- Clean up some msvc compile problems in a few files.
- Reorganize some headers to make them better match the Platform SDK.
- Move InlineIsEqualGUID to guiddef.h.
- Create new header files shlguid_undoc.h, shlobj_undoc.h, and shlwapi_undoc.h to hold undocumented types, functions, and GUIDs.
- Move some undocumented definitions declared in explorer_new/todo.h and undoc.h to new headers.
- Rename a few interfaces in explorer_new to the correct name
- Add definition of RBSTR_CHANGERECT to commctrl.h
- IDeskBarClient inherits from IOleWindow, not IUnknown
- HMONITOR was declared in both dxsdk/axextend.idl and wine/wined3d.idl, but not in wtypes.idl where it belongs
- Added Init and Term to CComModule
- Thanks to encoded for solving the browseui linking problem!
svn path=/trunk/; revision=43872
2009-10-31 14:25:45 +00:00
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
template <class T>
|
|
|
|
class CAtlModuleT : public CAtlModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-04-10 16:53:00 +00:00
|
|
|
HRESULT RegisterServer(BOOL bRegTypeLib = FALSE, const CLSID *pCLSID = NULL);
|
|
|
|
HRESULT UnregisterServer(BOOL bUnRegTypeLib, const CLSID *pCLSID = NULL);
|
|
|
|
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
virtual HRESULT AddCommonRGSReplacements(IRegistrarBase *pRegistrar)
|
|
|
|
{
|
|
|
|
return pRegistrar->AddReplacement(L"APPID", T::GetAppId());
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
static LPCOLESTR GetAppId()
|
|
|
|
{
|
|
|
|
return L"";
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CAtlComModule : public _ATL_COM_MODULE
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
CAtlComModule()
|
|
|
|
{
|
|
|
|
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)this, &m_hInstTypeLib);
|
2023-04-15 20:21:33 +00:00
|
|
|
|
|
|
|
m_ppAutoObjMapFirst = &__pobjMapEntryFirst + 1;
|
|
|
|
m_ppAutoObjMapLast = &__pobjMapEntryLast;
|
2015-05-03 15:10:09 +00:00
|
|
|
if (FAILED(m_csObjMap.Init()))
|
|
|
|
{
|
|
|
|
ATLASSERT(0);
|
|
|
|
CAtlBaseModule::m_bInitFailed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cbSize = sizeof(_ATL_COM_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
~CAtlComModule()
|
|
|
|
{
|
|
|
|
Term();
|
|
|
|
}
|
|
|
|
|
2016-04-10 16:53:00 +00:00
|
|
|
HRESULT RegisterServer(BOOL bRegTypeLib = FALSE, const CLSID *pCLSID = NULL)
|
|
|
|
{
|
|
|
|
return AtlComModuleRegisterServer(this, bRegTypeLib, pCLSID);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT UnregisterServer(BOOL bUnRegTypeLib, const CLSID *pCLSID = NULL)
|
|
|
|
{
|
|
|
|
return AtlComModuleUnregisterServer(this, bUnRegTypeLib, pCLSID);
|
|
|
|
}
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
void Term()
|
|
|
|
{
|
|
|
|
if (cbSize != 0)
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
for (_ATL_OBJMAP_ENTRY **iter = m_ppAutoObjMapFirst; iter < m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY *ptr = *iter;
|
|
|
|
if (!ptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!ptr->pCF)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ptr->pCF->Release();
|
|
|
|
ptr->pCF = NULL;
|
|
|
|
}
|
2015-05-03 15:10:09 +00:00
|
|
|
m_csObjMap.Term();
|
|
|
|
cbSize = 0;
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 20:21:33 +00:00
|
|
|
|
|
|
|
void ExecuteObjectMain(bool bStarting)
|
|
|
|
{
|
|
|
|
for (_ATL_OBJMAP_ENTRY **iter = m_ppAutoObjMapFirst; iter < m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
if (!*iter)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
(*iter)->pfnObjectMain(bStarting);
|
|
|
|
}
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
2019-04-06 20:37:13 +00:00
|
|
|
__declspec(selectany) CAtlComModule _AtlComModule;
|
|
|
|
|
|
|
|
|
2016-04-10 16:53:00 +00:00
|
|
|
template <class T>
|
|
|
|
HRESULT CAtlModuleT<T>::RegisterServer(BOOL bRegTypeLib, const CLSID *pCLSID)
|
|
|
|
{
|
|
|
|
return _AtlComModule.RegisterServer(bRegTypeLib, pCLSID);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
HRESULT CAtlModuleT<T>::UnregisterServer(BOOL bUnRegTypeLib, const CLSID *pCLSID)
|
|
|
|
{
|
|
|
|
return _AtlComModule.UnregisterServer(bUnRegTypeLib, pCLSID);
|
|
|
|
}
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
template <class T>
|
2023-04-15 20:21:33 +00:00
|
|
|
class CAtlDllModuleT
|
|
|
|
: public CAtlModuleT<T>
|
|
|
|
, private CAtlValidateModuleConfiguration<true, T>
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
CAtlDllModuleT()
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_AtlComModule.ExecuteObjectMain(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
~CAtlDllModuleT()
|
|
|
|
{
|
|
|
|
_AtlComModule.ExecuteObjectMain(false);
|
2015-05-03 15:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllCanUnloadNow()
|
|
|
|
{
|
|
|
|
T *pThis;
|
|
|
|
|
|
|
|
pThis = static_cast<T *>(this);
|
|
|
|
if (pThis->GetLockCount() == 0)
|
|
|
|
return S_OK;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
T *pThis;
|
|
|
|
|
|
|
|
pThis = static_cast<T *>(this);
|
|
|
|
return pThis->GetClassObject(rclsid, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllRegisterServer(BOOL bRegTypeLib = TRUE)
|
|
|
|
{
|
|
|
|
T *pThis;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
pThis = static_cast<T *>(this);
|
|
|
|
hResult = pThis->RegisterServer(bRegTypeLib);
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib = TRUE)
|
|
|
|
{
|
|
|
|
T *pThis;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
pThis = static_cast<T *>(this);
|
|
|
|
hResult = pThis->UnregisterServer(bUnRegTypeLib);
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return AtlComModuleGetClassObject(&_AtlComModule, rclsid, riid, ppv);
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
2017-10-22 20:25:03 +00:00
|
|
|
|
|
|
|
template <class T>
|
2023-04-15 20:21:33 +00:00
|
|
|
class CAtlExeModuleT
|
|
|
|
: public CAtlModuleT<T>
|
|
|
|
, private CAtlValidateModuleConfiguration<false, T>
|
2017-10-22 20:25:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DWORD m_dwMainThreadID;
|
|
|
|
//DWORD m_dwTimeOut;
|
|
|
|
//DWORD m_dwPause;
|
|
|
|
//bool m_bDelayShutdown;
|
|
|
|
|
|
|
|
CAtlExeModuleT()
|
|
|
|
:m_dwMainThreadID(::GetCurrentThreadId())
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_AtlComModule.ExecuteObjectMain(true);
|
2017-10-22 20:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~CAtlExeModuleT()
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_AtlComModule.ExecuteObjectMain(false);
|
2017-10-22 20:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int WinMain(int nShowCmd)
|
|
|
|
{
|
|
|
|
HRESULT hr = T::InitializeCom();
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
T* pThis = static_cast<T*>(this);
|
|
|
|
|
|
|
|
LPCTSTR lpCommandLine = GetCommandLine();
|
|
|
|
if (pThis->ParseCommandLine(lpCommandLine, &hr))
|
|
|
|
{
|
|
|
|
hr = pThis->Run(nShowCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
T::UninitializeCom();
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT Run(int nShowCmd = SW_HIDE)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
T* pThis = static_cast<T*>(this);
|
|
|
|
hr = pThis->PreMessageLoop(nShowCmd);
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
pThis->RunMessageLoop();
|
|
|
|
hr = pThis->PostMessageLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG Lock()
|
|
|
|
{
|
|
|
|
return CoAddRefServerProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG Unlock()
|
|
|
|
{
|
|
|
|
LONG lRet = CoReleaseServerProcess();
|
|
|
|
if (lRet == 0)
|
|
|
|
{
|
|
|
|
::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
|
|
|
|
}
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode)
|
|
|
|
{
|
|
|
|
// unimplemented!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT PreMessageLoop(int nShowCmd)
|
|
|
|
{
|
|
|
|
T* pThis = static_cast<T*>(this);
|
|
|
|
return pThis->RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunMessageLoop()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (GetMessage(&msg, 0, 0, 0) > 0)
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT PostMessageLoop()
|
|
|
|
{
|
|
|
|
T* pThis = static_cast<T*>(this);
|
|
|
|
return pThis->RevokeClassObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT RegisterClassObjects(DWORD dwClsContext, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
return AtlComModuleRegisterClassObjects(&_AtlComModule, dwClsContext, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT RevokeClassObjects()
|
|
|
|
{
|
|
|
|
return AtlComModuleRevokeClassObjects(&_AtlComModule);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT InitializeCom()
|
|
|
|
{
|
2023-04-19 18:27:31 +00:00
|
|
|
#if defined(_ATL_FREE_THREADED)
|
|
|
|
constexpr COINIT coInit = COINIT_MULTITHREADED;
|
|
|
|
#else
|
|
|
|
constexpr COINIT coInit = COINIT_APARTMENTTHREADED;
|
|
|
|
#endif
|
|
|
|
return ::CoInitializeEx(NULL, coInit);
|
2017-10-22 20:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void UninitializeCom()
|
|
|
|
{
|
|
|
|
::CoUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
class CComModule : public CAtlModuleT<CComModule>
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
_ATL_OBJMAP_ENTRY *m_pObjMap;
|
2009-10-20 12:26:51 +00:00
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
CComModule()
|
|
|
|
{
|
|
|
|
ATLASSERT(_pModule == NULL);
|
|
|
|
_pModule = this;
|
|
|
|
_pModule->m_pObjMap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
~CComModule()
|
|
|
|
{
|
|
|
|
_pModule = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE /* h */, const GUID *plibid)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY *objectMapEntry;
|
|
|
|
|
|
|
|
if (plibid != NULL)
|
|
|
|
m_libid = *plibid;
|
|
|
|
|
|
|
|
if (p != reinterpret_cast<_ATL_OBJMAP_ENTRY *>(-1))
|
|
|
|
{
|
|
|
|
m_pObjMap = p;
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
objectMapEntry = p;
|
|
|
|
while (objectMapEntry->pclsid != NULL)
|
|
|
|
{
|
|
|
|
objectMapEntry->pfnObjectMain(true);
|
|
|
|
objectMapEntry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 20:21:33 +00:00
|
|
|
|
|
|
|
for (_ATL_OBJMAP_ENTRY **iter = _AtlComModule.m_ppAutoObjMapFirst; iter < _AtlComModule.m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
if (*iter != NULL)
|
|
|
|
(*iter)->pfnObjectMain(true);
|
|
|
|
}
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Term()
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_ATL_OBJMAP_ENTRY *objectMapEntry;
|
2015-05-03 15:10:09 +00:00
|
|
|
|
|
|
|
if (m_pObjMap != NULL)
|
|
|
|
{
|
|
|
|
objectMapEntry = m_pObjMap;
|
|
|
|
while (objectMapEntry->pclsid != NULL)
|
|
|
|
{
|
|
|
|
if (objectMapEntry->pCF != NULL)
|
|
|
|
objectMapEntry->pCF->Release();
|
|
|
|
objectMapEntry->pCF = NULL;
|
|
|
|
objectMapEntry->pfnObjectMain(false);
|
|
|
|
objectMapEntry++;
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 20:21:33 +00:00
|
|
|
|
|
|
|
for (_ATL_OBJMAP_ENTRY **iter = _AtlComModule.m_ppAutoObjMapFirst; iter < _AtlComModule.m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
if (*iter != NULL)
|
|
|
|
(*iter)->pfnObjectMain(false);
|
|
|
|
}
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_ATL_OBJMAP_ENTRY *objectMapEntry;
|
|
|
|
HRESULT hResult;
|
2015-05-03 15:10:09 +00:00
|
|
|
|
|
|
|
ATLASSERT(ppv != NULL);
|
|
|
|
if (ppv == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
*ppv = NULL;
|
|
|
|
hResult = S_OK;
|
|
|
|
if (m_pObjMap != NULL)
|
|
|
|
{
|
|
|
|
objectMapEntry = m_pObjMap;
|
|
|
|
while (objectMapEntry->pclsid != NULL)
|
|
|
|
{
|
|
|
|
if (objectMapEntry->pfnGetClassObject != NULL && InlineIsEqualGUID(rclsid, *objectMapEntry->pclsid) != FALSE)
|
|
|
|
{
|
|
|
|
if (objectMapEntry->pCF == NULL)
|
|
|
|
{
|
|
|
|
CComCritSecLock<CComCriticalSection> lock(_AtlComModule.m_csObjMap, true);
|
|
|
|
|
|
|
|
if (objectMapEntry->pCF == NULL)
|
|
|
|
hResult = objectMapEntry->pfnGetClassObject(reinterpret_cast<void *>(objectMapEntry->pfnCreateInstance), IID_IUnknown, reinterpret_cast<LPVOID *>(&objectMapEntry->pCF));
|
|
|
|
}
|
|
|
|
if (objectMapEntry->pCF != NULL)
|
|
|
|
hResult = objectMapEntry->pCF->QueryInterface(riid, ppv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
objectMapEntry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hResult == S_OK && *ppv == NULL)
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
hResult = AtlComModuleGetClassObject(&_AtlComModule, rclsid, riid, ppv);
|
2015-05-03 15:10:09 +00:00
|
|
|
}
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT RegisterServer(BOOL bRegTypeLib = FALSE, const CLSID *pCLSID = NULL)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY *objectMapEntry;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
hResult = S_OK;
|
|
|
|
objectMapEntry = m_pObjMap;
|
|
|
|
if (objectMapEntry != NULL)
|
|
|
|
{
|
|
|
|
while (objectMapEntry->pclsid != NULL)
|
|
|
|
{
|
|
|
|
if (pCLSID == NULL || IsEqualGUID(*pCLSID, *objectMapEntry->pclsid) != FALSE)
|
|
|
|
{
|
|
|
|
hResult = objectMapEntry->pfnUpdateRegistry(TRUE);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
objectMapEntry++;
|
|
|
|
}
|
|
|
|
}
|
2016-04-10 16:53:00 +00:00
|
|
|
if (SUCCEEDED(hResult))
|
|
|
|
hResult = CAtlModuleT<CComModule>::RegisterServer(bRegTypeLib, pCLSID);
|
2015-05-03 15:10:09 +00:00
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT UnregisterServer(BOOL bUnRegTypeLib, const CLSID *pCLSID = NULL)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY *objectMapEntry;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
hResult = S_OK;
|
|
|
|
objectMapEntry = m_pObjMap;
|
|
|
|
if (objectMapEntry != NULL)
|
|
|
|
{
|
|
|
|
while (objectMapEntry->pclsid != NULL)
|
|
|
|
{
|
|
|
|
if (pCLSID == NULL || IsEqualGUID(*pCLSID, *objectMapEntry->pclsid) != FALSE)
|
|
|
|
{
|
|
|
|
hResult = objectMapEntry->pfnUpdateRegistry(FALSE); //unregister
|
|
|
|
if (FAILED(hResult))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
objectMapEntry++;
|
|
|
|
}
|
|
|
|
}
|
2016-04-10 16:53:00 +00:00
|
|
|
if (SUCCEEDED(hResult))
|
|
|
|
hResult = CAtlModuleT<CComModule>::UnregisterServer(bUnRegTypeLib, pCLSID);
|
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllCanUnloadNow()
|
|
|
|
{
|
|
|
|
if (GetLockCount() == 0)
|
|
|
|
return S_OK;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return GetClassObject(rclsid, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllRegisterServer(BOOL bRegTypeLib = TRUE)
|
|
|
|
{
|
|
|
|
return RegisterServer(bRegTypeLib);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib = TRUE)
|
|
|
|
{
|
|
|
|
return UnregisterServer(bUnRegTypeLib);
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class CAtlWinModule : public _ATL_WIN_MODULE
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 15:10:09 +00:00
|
|
|
CAtlWinModule()
|
|
|
|
{
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
hResult = AtlWinModuleInit(this);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
{
|
|
|
|
CAtlBaseModule::m_bInitFailed = true;
|
|
|
|
ATLASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~CAtlWinModule()
|
|
|
|
{
|
|
|
|
Term();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Term()
|
|
|
|
{
|
2009-10-20 12:26:51 +00:00
|
|
|
AtlWinModuleTerm(this, _AtlBaseModule.GetModuleInstance());
|
2015-05-03 15:10:09 +00:00
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
void AddCreateWndData(_AtlCreateWndData *pData, void *pObject)
|
|
|
|
{
|
|
|
|
AtlWinModuleAddCreateWndData(this, pData, pObject);
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
void *ExtractCreateWndData()
|
|
|
|
{
|
|
|
|
return AtlWinModuleExtractCreateWndData(this);
|
|
|
|
}
|
2009-10-20 12:26:51 +00:00
|
|
|
};
|
|
|
|
|
2019-04-06 20:37:13 +00:00
|
|
|
__declspec(selectany) CAtlWinModule _AtlWinModule;
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2016-03-17 18:05:44 +00:00
|
|
|
class CComAllocator
|
2015-10-18 10:46:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-03-17 18:05:44 +00:00
|
|
|
static void* Allocate(_In_ size_t size)
|
2015-10-18 10:46:11 +00:00
|
|
|
{
|
2016-03-17 18:05:44 +00:00
|
|
|
return ::CoTaskMemAlloc(size);
|
2015-10-18 10:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 18:05:44 +00:00
|
|
|
static void* Reallocate(_In_opt_ void* ptr, _In_ size_t size)
|
2015-10-18 10:46:11 +00:00
|
|
|
{
|
2016-03-17 18:05:44 +00:00
|
|
|
return ::CoTaskMemRealloc(ptr, size);
|
2015-10-18 10:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 18:05:44 +00:00
|
|
|
static void Free(_In_opt_ void* ptr)
|
2015-10-18 10:46:11 +00:00
|
|
|
{
|
2016-03-17 18:05:44 +00:00
|
|
|
::CoTaskMemFree(ptr);
|
2015-10-18 10:46:11 +00:00
|
|
|
}
|
2016-03-17 18:05:44 +00:00
|
|
|
};
|
2015-10-18 10:46:11 +00:00
|
|
|
|
2016-08-10 19:34:38 +00:00
|
|
|
class CRegKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HKEY m_hKey;
|
2016-10-17 12:50:54 +00:00
|
|
|
#if 0
|
|
|
|
// FIXME & TODO:
|
|
|
|
CAtlTransactionManager* m_pTM;
|
|
|
|
#endif
|
2016-08-10 19:34:38 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
CRegKey() noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
: m_hKey(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
CRegKey(CRegKey& key) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
: m_hKey(key.Detach())
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
explicit CRegKey(HKEY hKey) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
: m_hKey(hKey)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// FIXME & TODO:
|
2023-10-16 06:40:17 +00:00
|
|
|
CRegKey(CAtlTransactionManager* pTM) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
...
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
2016-10-17 12:50:54 +00:00
|
|
|
#endif
|
2016-08-10 19:34:38 +00:00
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
~CRegKey() noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2021-06-24 21:50:01 +00:00
|
|
|
Close();
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
void Attach(HKEY hKey) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
m_hKey = hKey;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG Close() noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
if (m_hKey)
|
|
|
|
{
|
|
|
|
HKEY hKey = Detach();
|
2016-10-17 12:50:54 +00:00
|
|
|
return ::RegCloseKey(hKey);
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
HKEY Detach() noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
HKEY hKey = m_hKey;
|
|
|
|
m_hKey = NULL;
|
|
|
|
return hKey;
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName,
|
2023-10-16 06:40:17 +00:00
|
|
|
REGSAM samDesired = KEY_READ | KEY_WRITE) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
ATLASSERT(hKeyParent);
|
|
|
|
ATLASSERT(lpszKeyName);
|
2016-08-10 19:34:38 +00:00
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
HKEY hKey = NULL;
|
2019-04-19 23:35:39 +00:00
|
|
|
LONG lRes = ::RegOpenKeyEx(hKeyParent, lpszKeyName, 0, samDesired, &hKey);
|
2016-08-10 19:34:38 +00:00
|
|
|
if (lRes == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
m_hKey = hKey;
|
|
|
|
}
|
|
|
|
return lRes;
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName,
|
|
|
|
LPTSTR lpszClass = REG_NONE,
|
|
|
|
DWORD dwOptions = REG_OPTION_NON_VOLATILE,
|
|
|
|
REGSAM samDesired = KEY_READ | KEY_WRITE,
|
|
|
|
LPSECURITY_ATTRIBUTES lpSecAttr = NULL,
|
2023-10-16 06:40:17 +00:00
|
|
|
LPDWORD lpdwDisposition = NULL) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
ATLASSERT(hKeyParent);
|
|
|
|
ATLASSERT(lpszKeyName);
|
2016-08-10 19:34:38 +00:00
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
HKEY hKey = NULL;
|
2019-04-19 23:35:39 +00:00
|
|
|
LONG lRes = ::RegCreateKeyEx(hKeyParent, lpszKeyName, 0, lpszClass,
|
2016-10-17 12:50:54 +00:00
|
|
|
dwOptions, samDesired, lpSecAttr, &hKey,
|
|
|
|
lpdwDisposition);
|
2016-08-10 19:34:38 +00:00
|
|
|
if (lRes == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
m_hKey = hKey;
|
|
|
|
}
|
|
|
|
return lRes;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG QueryValue(LPCTSTR pszValueName, DWORD* pdwType, void* pData, ULONG* pnBytes) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
return ::RegQueryValueEx(m_hKey, pszValueName, NULL, pdwType, (LPBYTE)pData, pnBytes);
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG QueryDWORDValue(LPCTSTR pszValueName, DWORD& dwValue) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
ULONG size = sizeof(DWORD);
|
|
|
|
DWORD type = 0;
|
|
|
|
LONG lRet = QueryValue(pszValueName, &type, &dwValue, &size);
|
|
|
|
|
|
|
|
if (lRet == ERROR_SUCCESS && type != REG_DWORD)
|
|
|
|
lRet = ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG QueryBinaryValue(LPCTSTR pszValueName, void* pValue, ULONG* pnBytes) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
DWORD type = 0;
|
|
|
|
LONG lRet = QueryValue(pszValueName, &type, pValue, pnBytes);
|
|
|
|
|
|
|
|
if (lRet == ERROR_SUCCESS && type != REG_BINARY)
|
|
|
|
lRet = ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG QueryStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
ULONG size = (*pnChars) * sizeof(TCHAR);
|
|
|
|
DWORD type = 0;
|
|
|
|
LONG lRet = QueryValue(pszValueName, &type, pszValue, &size);
|
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
if (lRet == ERROR_SUCCESS && type != REG_SZ && type != REG_EXPAND_SZ)
|
2016-08-10 19:34:38 +00:00
|
|
|
lRet = ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
*pnChars = size / sizeof(TCHAR);
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG QueryGUIDValue(LPCTSTR pszValueName, GUID& guidValue) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
OLECHAR buf[40] = {0};
|
|
|
|
ULONG nChars = 39;
|
|
|
|
LONG lRet;
|
|
|
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
lRet = QueryStringValue(pszValueName, buf, &nChars);
|
|
|
|
#else
|
|
|
|
CHAR bufA[40] = {0};
|
|
|
|
lRet = QueryStringValue(pszValueName, bufA, &nChars);
|
|
|
|
if (lRet != ERROR_SUCCESS)
|
|
|
|
return lRet;
|
|
|
|
if (!::MultiByteToWideChar(CP_THREAD_ACP, 0, bufA, -1, buf, 39))
|
|
|
|
lRet = ERROR_INVALID_DATA;
|
|
|
|
#endif
|
|
|
|
if (lRet != ERROR_SUCCESS)
|
|
|
|
return lRet;
|
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
if (!SUCCEEDED(::CLSIDFromString(buf, &guidValue)))
|
2016-08-10 19:34:38 +00:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG QueryQWORDValue(LPCTSTR pszValueName, ULONGLONG& qwValue) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ULONG size = sizeof(ULONGLONG);
|
|
|
|
DWORD type = 0;
|
|
|
|
LONG lRet = QueryValue(pszValueName, &type, &qwValue, &size);
|
|
|
|
|
|
|
|
if (lRet == ERROR_SUCCESS && type != REG_QWORD)
|
|
|
|
lRet = ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG QueryMultiStringValue(LPCTSTR pszValueName, LPTSTR pszValue,
|
2023-10-16 06:40:17 +00:00
|
|
|
ULONG* pnChars) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ULONG size = (*pnChars) * sizeof(TCHAR);
|
|
|
|
DWORD type;
|
|
|
|
LONG lRet = QueryValue(pszValueName, &type, pszValue, &size);
|
|
|
|
|
|
|
|
if (lRet == ERROR_SUCCESS && type != REG_MULTI_SZ)
|
|
|
|
lRet = ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
*pnChars = size / sizeof(TCHAR);
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetValue(LPCTSTR pszValueName, DWORD dwType, const void* pValue, ULONG nBytes) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
ATLASSERT(m_hKey);
|
2019-04-19 23:35:39 +00:00
|
|
|
return ::RegSetValueEx(m_hKey, pszValueName, 0, dwType, (const BYTE*)pValue, nBytes);
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
return SetValue(pszValueName, REG_DWORD, &dwValue, sizeof(DWORD));
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType = REG_SZ) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2019-01-06 22:14:09 +00:00
|
|
|
SIZE_T length;
|
2016-10-17 12:50:54 +00:00
|
|
|
switch (dwType)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
length = (_tcslen(pszValue) + 1) * sizeof(TCHAR);
|
|
|
|
return SetValue(pszValueName, dwType, pszValue, length);
|
|
|
|
case REG_MULTI_SZ:
|
|
|
|
return SetMultiStringValue(pszValueName, pszValue);
|
|
|
|
default:
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
OLECHAR buf[40] = {0};
|
2016-10-17 12:50:54 +00:00
|
|
|
::StringFromGUID2(guidValue, buf, 39);
|
2016-08-10 19:34:38 +00:00
|
|
|
#ifdef UNICODE
|
|
|
|
return SetStringValue(pszValueName, buf);
|
|
|
|
#else
|
|
|
|
CHAR bufA[40] = {0};
|
|
|
|
::WideCharToMultiByte(CP_THREAD_ACP, 0, buf, -1, bufA, 40, NULL, NULL);
|
|
|
|
return SetStringValue(pszValueName, bufA);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetBinaryValue(LPCTSTR pszValueName, const void* pValue, ULONG nBytes) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
return SetValue(pszValueName, REG_BINARY, pValue, nBytes);
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ULONG dwSize = CRegKey::_GetMultiStringSize(pszValue);
|
|
|
|
return SetValue(pszValueName, REG_MULTI_SZ, pszValue, dwSize);
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ULONG dwSize = sizeof(ULONGLONG);
|
|
|
|
return SetValue(pszValueName, REG_QWORD, &qwValue, dwSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG NotifyChangeKeyValue(BOOL bWatchSubtree, DWORD dwNotifyFilter,
|
2023-10-16 06:40:17 +00:00
|
|
|
HANDLE hEvent, BOOL bAsync = TRUE) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
LONG ret = ::RegNotifyChangeKeyValue(m_hKey, bWatchSubtree,
|
|
|
|
dwNotifyFilter, hEvent, bAsync);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG Flush() noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
LONG ret = ::RegFlushKey(m_hKey);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName,
|
|
|
|
LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL)
|
|
|
|
{
|
|
|
|
CRegKey key;
|
|
|
|
LONG lRet = key.Create(hKeyParent, lpszKeyName);
|
|
|
|
if (lRet == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
lRet = key.SetStringValue(lpszValueName, lpszValue);
|
|
|
|
}
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue,
|
2023-10-16 06:40:17 +00:00
|
|
|
LPCTSTR lpszValueName = NULL) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
CRegKey key;
|
|
|
|
LONG lRet = key.Create(m_hKey, lpszKeyName);
|
|
|
|
if (lRet == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
lRet = key.SetStringValue(lpszValueName, lpszValue);
|
|
|
|
}
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG DeleteValue(LPCTSTR lpszValue) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
return ::RegDeleteValue(m_hKey, lpszValue);
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG DeleteSubKey(LPCTSTR lpszSubKey) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2016-10-17 12:50:54 +00:00
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
ATLASSERT(lpszSubKey);
|
|
|
|
return ::RegDeleteKey(m_hKey, lpszSubKey);
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
LONG RecurseDeleteKey(LPCTSTR lpszKey) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
ATLASSERT(lpszKey);
|
|
|
|
return CRegKey::_DoDeleteKeyTree(m_hKey, lpszKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG EnumKey(DWORD iIndex, LPTSTR pszName, LPDWORD pnNameLength,
|
2023-10-16 06:40:17 +00:00
|
|
|
FILETIME* pftLastWriteTime = NULL) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
LONG ret = ::RegEnumKeyEx(m_hKey, iIndex, pszName, pnNameLength, NULL,
|
|
|
|
NULL, NULL, pftLastWriteTime);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG GetKeySecurity(SECURITY_INFORMATION si, PSECURITY_DESCRIPTOR psd,
|
2023-10-16 06:40:17 +00:00
|
|
|
LPDWORD pnBytes) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
LONG ret = ::RegGetKeySecurity(m_hKey, si, psd, pnBytes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG SetKeySecurity(SECURITY_INFORMATION si,
|
2023-10-16 06:40:17 +00:00
|
|
|
PSECURITY_DESCRIPTOR psd) noexcept
|
2016-10-17 12:50:54 +00:00
|
|
|
{
|
|
|
|
ATLASSERT(m_hKey);
|
|
|
|
LONG ret = ::RegSetKeySecurity(m_hKey, si, psd);
|
|
|
|
return ret;
|
2016-08-10 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
operator HKEY() const noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
|
|
|
return m_hKey;
|
|
|
|
}
|
|
|
|
|
2023-10-16 06:40:17 +00:00
|
|
|
CRegKey& operator=(CRegKey& key) noexcept
|
2016-08-10 19:34:38 +00:00
|
|
|
{
|
2021-06-24 21:50:01 +00:00
|
|
|
if (m_hKey != key.m_hKey)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
Attach(key.Detach());
|
|
|
|
}
|
2016-08-10 19:34:38 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
protected:
|
|
|
|
// get the total size of a multistring
|
|
|
|
static ULONG _GetMultiStringSize(LPCTSTR pszz)
|
|
|
|
{
|
2019-05-30 15:12:28 +00:00
|
|
|
size_t count = 0;
|
2016-10-17 12:50:54 +00:00
|
|
|
do
|
|
|
|
{
|
2019-05-30 15:12:28 +00:00
|
|
|
size_t len = _tcslen(pszz);
|
2016-10-17 12:50:54 +00:00
|
|
|
count += len + 1;
|
|
|
|
pszz += len + 1;
|
|
|
|
} while (*pszz != TEXT('\0'));
|
|
|
|
++count;
|
2020-03-17 19:53:26 +00:00
|
|
|
ATLASSERT(count * sizeof(TCHAR) <= ULONG_MAX);
|
2019-05-30 15:12:28 +00:00
|
|
|
return (ULONG)count * sizeof(TCHAR);
|
2016-10-17 12:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete key recursively
|
|
|
|
static LONG _DoDeleteKeyTree(HKEY hParentKey, LPCTSTR lpszKey)
|
|
|
|
{
|
|
|
|
ATLASSERT(hParentKey);
|
|
|
|
ATLASSERT(lpszKey);
|
2016-08-10 19:34:38 +00:00
|
|
|
|
2016-10-17 12:50:54 +00:00
|
|
|
// open the key
|
|
|
|
CRegKey key;
|
|
|
|
LONG ret = key.Open(hParentKey, lpszKey);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
return ret; // failure
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the longest length of subkey names
|
|
|
|
DWORD NameMax;
|
|
|
|
ret = ::RegQueryInfoKey(key, NULL, NULL, NULL, NULL, &NameMax, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
return ret; // failure
|
|
|
|
}
|
|
|
|
++NameMax; // for NUL
|
|
|
|
|
|
|
|
// allocate the string buffer for names if necessary
|
|
|
|
TCHAR szNameBuf[MAX_PATH], *pszName;
|
|
|
|
if (NameMax > MAX_PATH)
|
|
|
|
{
|
|
|
|
pszName = (TCHAR *)malloc(NameMax * sizeof(TCHAR));
|
|
|
|
ATLASSERT(pszName);
|
|
|
|
if (pszName == NULL)
|
|
|
|
{
|
|
|
|
return ERROR_OUTOFMEMORY; // failure
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NameMax = MAX_PATH;
|
|
|
|
pszName = szNameBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enumerate every subkey and delete
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DWORD Count = NameMax;
|
|
|
|
ret = key.EnumKey(0, pszName, &Count);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (ret == ERROR_NO_MORE_ITEMS)
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = CRegKey::_DoDeleteKeyTree(key, pszName);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// close key
|
|
|
|
key.Close();
|
|
|
|
|
|
|
|
// delete the subkey
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
ret = ::RegDeleteKey(hParentKey, lpszKey);
|
|
|
|
|
|
|
|
// delete the buffer if any
|
|
|
|
if (pszName != szNameBuf)
|
|
|
|
free(pszName);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
2015-10-18 10:46:11 +00:00
|
|
|
|
2016-03-17 18:05:44 +00:00
|
|
|
template<class T>
|
|
|
|
class CComHeapPtr : public CHeapPtr<T, CComAllocator>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CComHeapPtr()
|
2015-10-18 10:46:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-17 18:05:44 +00:00
|
|
|
explicit CComHeapPtr(T *lp) :
|
|
|
|
CHeapPtr<T, CComAllocator>(lp)
|
2015-10-18 10:46:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
inline HRESULT __stdcall AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID &iid, LPDWORD pdw)
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
CComPtr<IConnectionPointContainer> container;
|
|
|
|
CComPtr<IConnectionPoint> connectionPoint;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
if (pUnkCP == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
hResult = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void **)&container);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
hResult = container->FindConnectionPoint(iid, &connectionPoint);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
return connectionPoint->Advise(pUnk, pdw);
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline HRESULT __stdcall AtlUnadvise(IUnknown *pUnkCP, const IID &iid, DWORD dw)
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
CComPtr<IConnectionPointContainer> container;
|
|
|
|
CComPtr<IConnectionPoint> connectionPoint;
|
|
|
|
HRESULT hResult;
|
2015-05-03 15:10:09 +00:00
|
|
|
|
|
|
|
if (pUnkCP == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
hResult = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void **)&container);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
hResult = container->FindConnectionPoint(iid, &connectionPoint);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
return connectionPoint->Unadvise(dw);
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline HRESULT __stdcall AtlInternalQueryInterface(void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
int i;
|
|
|
|
IUnknown *resultInterface;
|
|
|
|
HRESULT hResult;
|
|
|
|
|
|
|
|
ATLASSERT(pThis != NULL && pEntries != NULL);
|
|
|
|
if (pThis == NULL || pEntries == NULL)
|
|
|
|
return E_INVALIDARG;
|
2022-12-13 08:36:02 +00:00
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
if (ppvObject == NULL)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (InlineIsEqualUnknown(iid))
|
|
|
|
{
|
|
|
|
resultInterface = reinterpret_cast<IUnknown *>(reinterpret_cast<char *>(pThis) + pEntries[0].dw);
|
|
|
|
*ppvObject = resultInterface;
|
|
|
|
resultInterface->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (pEntries[i].pFunc != 0)
|
|
|
|
{
|
|
|
|
if (pEntries[i].piid == NULL || InlineIsEqualGUID(iid, *pEntries[i].piid))
|
|
|
|
{
|
|
|
|
if (pEntries[i].pFunc == reinterpret_cast<_ATL_CREATORARGFUNC *>(1))
|
|
|
|
{
|
|
|
|
ATLASSERT(pEntries[i].piid != NULL);
|
|
|
|
resultInterface = reinterpret_cast<IUnknown *>(reinterpret_cast<char *>(pThis) + pEntries[i].dw);
|
|
|
|
*ppvObject = resultInterface;
|
|
|
|
resultInterface->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hResult = pEntries[i].pFunc(pThis, iid, ppvObject, 0);
|
2017-12-18 22:15:46 +00:00
|
|
|
if (hResult == S_OK)
|
2015-05-03 15:10:09 +00:00
|
|
|
return hResult;
|
2017-12-18 22:15:46 +00:00
|
|
|
if (FAILED(hResult) && pEntries[i].piid != NULL)
|
|
|
|
break;
|
2015-05-03 15:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline HRESULT __stdcall AtlWinModuleInit(_ATL_WIN_MODULE *pWinModule)
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
if (pWinModule == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
pWinModule->m_pCreateWndList = NULL;
|
|
|
|
return pWinModule->m_csWindowCreate.Init();
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline HRESULT __stdcall AtlWinModuleTerm(_ATL_WIN_MODULE *pWinModule, HINSTANCE hInst)
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
if (pWinModule == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
pWinModule->m_csWindowCreate.Term();
|
|
|
|
return S_OK;
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void __stdcall AtlWinModuleAddCreateWndData(_ATL_WIN_MODULE *pWinModule, _AtlCreateWndData *pData, void *pObject)
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
CComCritSecLock<CComCriticalSection> lock(pWinModule->m_csWindowCreate, true);
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
ATLASSERT(pWinModule != NULL);
|
|
|
|
ATLASSERT(pObject != NULL);
|
2009-10-20 12:26:51 +00:00
|
|
|
|
2015-05-03 15:10:09 +00:00
|
|
|
pData->m_pThis = pObject;
|
|
|
|
pData->m_dwThreadID = ::GetCurrentThreadId();
|
|
|
|
pData->m_pNext = pWinModule->m_pCreateWndList;
|
|
|
|
pWinModule->m_pCreateWndList = pData;
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void *__stdcall AtlWinModuleExtractCreateWndData(_ATL_WIN_MODULE *pWinModule)
|
|
|
|
{
|
2015-05-03 15:10:09 +00:00
|
|
|
CComCritSecLock<CComCriticalSection> lock(pWinModule->m_csWindowCreate, true);
|
|
|
|
void *result;
|
|
|
|
_AtlCreateWndData *currentEntry;
|
|
|
|
_AtlCreateWndData **previousLink;
|
|
|
|
DWORD threadID;
|
|
|
|
|
|
|
|
ATLASSERT(pWinModule != NULL);
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
threadID = GetCurrentThreadId();
|
|
|
|
currentEntry = pWinModule->m_pCreateWndList;
|
|
|
|
previousLink = &pWinModule->m_pCreateWndList;
|
|
|
|
while (currentEntry != NULL)
|
|
|
|
{
|
|
|
|
if (currentEntry->m_dwThreadID == threadID)
|
|
|
|
{
|
|
|
|
*previousLink = currentEntry->m_pNext;
|
|
|
|
result = currentEntry->m_pThis;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
previousLink = ¤tEntry->m_pNext;
|
|
|
|
currentEntry = currentEntry->m_pNext;
|
|
|
|
}
|
|
|
|
return result;
|
2009-10-20 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 16:53:00 +00:00
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI AtlLoadTypeLib(HINSTANCE inst, LPCOLESTR lpszIndex,
|
|
|
|
BSTR *pbstrPath, ITypeLib **ppTypeLib)
|
|
|
|
{
|
|
|
|
size_t index_len = lpszIndex ? wcslen(lpszIndex) : 0;
|
|
|
|
CComHeapPtr<WCHAR> path;
|
|
|
|
path.Allocate(MAX_PATH + index_len + wcslen(L".tlb"));
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
size_t path_len = GetModuleFileNameW(inst, path, MAX_PATH);
|
|
|
|
if (!path_len)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
if (index_len)
|
|
|
|
wcscat(path, lpszIndex);
|
|
|
|
|
|
|
|
CComPtr<ITypeLib> typelib;
|
|
|
|
HRESULT hResult = LoadTypeLib(path, &typelib);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
{
|
|
|
|
WCHAR *ptr;
|
|
|
|
for (ptr = path+path_len-1; ptr > path && *ptr != '\\' && *ptr != '.'; ptr--)
|
|
|
|
;
|
|
|
|
if (*ptr != '.')
|
|
|
|
ptr = (WCHAR*)path + path_len;
|
|
|
|
wcscpy(ptr, L".tlb");
|
|
|
|
|
|
|
|
hResult = LoadTypeLib(path, &typelib);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hResult))
|
|
|
|
{
|
|
|
|
*pbstrPath = SysAllocString(path);
|
|
|
|
if (!*pbstrPath)
|
|
|
|
{
|
|
|
|
typelib.Release();
|
|
|
|
hResult = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
*ppTypeLib = typelib.Detach();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI AtlRegisterTypeLib(HINSTANCE inst, const WCHAR *index)
|
|
|
|
{
|
|
|
|
CComBSTR path;
|
|
|
|
CComPtr<ITypeLib> typelib;
|
|
|
|
HRESULT hResult = AtlLoadTypeLib(inst, index, &path, &typelib);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
return RegisterTypeLib(typelib, path, NULL); /* FIXME: pass help directory */
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI AtlRegisterClassCategoriesHelper(REFCLSID clsid, const _ATL_CATMAP_ENTRY *catmap, BOOL reg)
|
|
|
|
{
|
|
|
|
if (!catmap)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
CComPtr<ICatRegister> catreg;
|
|
|
|
|
|
|
|
HRESULT hResult = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&catreg);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
for (const _ATL_CATMAP_ENTRY *iter = catmap; iter->iType != _ATL_CATMAP_ENTRY_END; iter++)
|
|
|
|
{
|
|
|
|
CATID catid = *iter->pcatid;
|
|
|
|
|
|
|
|
if (iter->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
if (reg)
|
|
|
|
hResult = catreg->RegisterClassImplCategories(clsid, 1, &catid);
|
|
|
|
else
|
|
|
|
hResult = catreg->UnRegisterClassImplCategories(clsid, 1, &catid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (reg)
|
|
|
|
hResult = catreg->RegisterClassReqCategories(clsid, 1, &catid);
|
|
|
|
else
|
|
|
|
hResult = catreg->UnRegisterClassReqCategories(clsid, 1, &catid);
|
|
|
|
}
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reg)
|
|
|
|
{
|
|
|
|
WCHAR reg_path[256] = L"CLSID\\";
|
|
|
|
|
|
|
|
StringFromGUID2(clsid, reg_path + wcslen(reg_path), 64);
|
|
|
|
wcscat(reg_path, L"\\");
|
|
|
|
WCHAR* ptr = reg_path + wcslen(reg_path);
|
|
|
|
|
|
|
|
wcscpy(ptr, L"Implemented Categories");
|
|
|
|
RegDeleteKeyW(HKEY_CLASSES_ROOT, reg_path);
|
|
|
|
|
|
|
|
wcscpy(ptr, L"Required Categories");
|
|
|
|
RegDeleteKeyW(HKEY_CLASSES_ROOT, reg_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Adapted from dll/win32/atl80/atl80.c
|
|
|
|
inline HRESULT __stdcall AtlComModuleRegisterServer(_ATL_COM_MODULE *mod, BOOL bRegTypeLib, const CLSID *clsid)
|
|
|
|
{
|
|
|
|
HRESULT hResult = S_OK;
|
|
|
|
|
|
|
|
for (_ATL_OBJMAP_ENTRY ** iter = mod->m_ppAutoObjMapFirst; iter < mod->m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
if (!*iter)
|
|
|
|
continue;
|
|
|
|
_ATL_OBJMAP_ENTRY* entry = *iter;
|
|
|
|
if (clsid && !IsEqualCLSID(*entry->pclsid, *clsid))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hResult = entry->pfnUpdateRegistry(TRUE);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
const _ATL_CATMAP_ENTRY *catmap = entry->pfnGetCategoryMap();
|
|
|
|
if (catmap)
|
|
|
|
{
|
|
|
|
hResult = AtlRegisterClassCategoriesHelper(*entry->pclsid, catmap, TRUE);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bRegTypeLib)
|
|
|
|
{
|
|
|
|
hResult = AtlRegisterTypeLib(mod->m_hInstTypeLib, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI AtlComModuleUnregisterServer(_ATL_COM_MODULE *mod, BOOL bUnRegTypeLib, const CLSID *clsid)
|
|
|
|
{
|
|
|
|
HRESULT hResult = S_OK;
|
|
|
|
|
|
|
|
for (_ATL_OBJMAP_ENTRY **iter = mod->m_ppAutoObjMapFirst; iter < mod->m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
if (!*iter)
|
|
|
|
continue;
|
|
|
|
_ATL_OBJMAP_ENTRY* entry = *iter;
|
|
|
|
if (clsid && !IsEqualCLSID(*entry->pclsid, *clsid))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const _ATL_CATMAP_ENTRY *catmap = entry->pfnGetCategoryMap();
|
|
|
|
if (catmap)
|
|
|
|
{
|
|
|
|
hResult = AtlRegisterClassCategoriesHelper(*entry->pclsid, catmap, FALSE);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
hResult = entry->pfnUpdateRegistry(FALSE);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bUnRegTypeLib)
|
|
|
|
{
|
|
|
|
CComPtr<ITypeLib> typelib;
|
|
|
|
TLIBATTR *attr;
|
|
|
|
CComBSTR path;
|
|
|
|
|
|
|
|
hResult = AtlLoadTypeLib(mod->m_hInstTypeLib, NULL, &path, &typelib);
|
|
|
|
if (FAILED(hResult))
|
|
|
|
return hResult;
|
|
|
|
|
|
|
|
hResult = typelib->GetLibAttr(&attr);
|
|
|
|
if (SUCCEEDED(hResult))
|
|
|
|
{
|
|
|
|
hResult = UnRegisterTypeLib(attr->guid, attr->wMajorVerNum, attr->wMinorVerNum, attr->lcid, attr->syskind);
|
|
|
|
typelib->ReleaseTLibAttr(attr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-22 20:25:03 +00:00
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI AtlComModuleRegisterClassObjects(_ATL_COM_MODULE *module, DWORD context, DWORD flags)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY **iter;
|
|
|
|
IUnknown* unk = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!module)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (iter = module->m_ppAutoObjMapFirst; iter < module->m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_ATL_OBJMAP_ENTRY *ptr = *iter;
|
|
|
|
if (!ptr)
|
2017-10-22 20:25:03 +00:00
|
|
|
continue;
|
|
|
|
|
2023-04-15 20:21:33 +00:00
|
|
|
if (!ptr->pfnGetClassObject)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hr = ptr->pfnGetClassObject((void*)ptr->pfnCreateInstance, IID_IUnknown, (void**)&unk);
|
2017-10-22 20:25:03 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2023-04-15 20:21:33 +00:00
|
|
|
hr = CoRegisterClassObject(*ptr->pclsid, unk, context, flags, &ptr->dwRegister);
|
2017-10-22 20:25:03 +00:00
|
|
|
unk->Release();
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI AtlComModuleRevokeClassObjects(_ATL_COM_MODULE *module)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY **iter;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!module)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (iter = module->m_ppAutoObjMapFirst; iter < module->m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
2023-04-15 20:21:33 +00:00
|
|
|
_ATL_OBJMAP_ENTRY *ptr = *iter;
|
|
|
|
if (!ptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hr = CoRevokeClassObject(ptr->dwRegister);
|
2017-10-22 20:25:03 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-04-15 20:21:33 +00:00
|
|
|
// Adapted from dll/win32/atl/atl.c
|
|
|
|
inline HRESULT WINAPI
|
|
|
|
AtlComModuleGetClassObject(_ATL_COM_MODULE *pm, REFCLSID rclsid, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
if (!pm)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (_ATL_OBJMAP_ENTRY **iter = pm->m_ppAutoObjMapFirst; iter < pm->m_ppAutoObjMapLast; iter++)
|
|
|
|
{
|
|
|
|
_ATL_OBJMAP_ENTRY *ptr = *iter;
|
|
|
|
if (!ptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (IsEqualCLSID(*ptr->pclsid, rclsid) && ptr->pfnGetClassObject)
|
|
|
|
{
|
|
|
|
HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
|
|
|
|
if (!ptr->pCF)
|
|
|
|
{
|
|
|
|
CComCritSecLock<CComCriticalSection> lock(_AtlComModule.m_csObjMap, true);
|
|
|
|
if (!ptr->pCF)
|
|
|
|
{
|
|
|
|
hr = ptr->pfnGetClassObject((void *)ptr->pfnCreateInstance, IID_IUnknown, (void **)&ptr->pCF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ptr->pCF)
|
|
|
|
hr = ptr->pCF->QueryInterface(riid, ppv);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-20 12:26:51 +00:00
|
|
|
}; // namespace ATL
|
|
|
|
|
|
|
|
#ifndef _ATL_NO_AUTOMATIC_NAMESPACE
|
|
|
|
using namespace ATL;
|
|
|
|
#endif //!_ATL_NO_AUTOMATIC_NAMESPACE
|