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.

6725 lines
193 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLBASE_H__
  11. #define __ATLBASE_H__
  12. #ifndef __cplusplus
  13. #error ATL requires C++ compilation (use a .cpp suffix)
  14. #endif
  15. #ifndef _ATL_NO_PRAGMA_WARNINGS
  16. #pragma warning(disable: 4201) // nameless unions are part of C++
  17. #pragma warning(disable: 4127) // constant expression
  18. #pragma warning(disable: 4505) // unreferenced local function has been removed
  19. #pragma warning(disable: 4512) // can't generate assignment operator (so what?)
  20. #pragma warning(disable: 4514) // unreferenced inlines are common
  21. #pragma warning(disable: 4103) // pragma pack
  22. #pragma warning(disable: 4702) // unreachable code
  23. #pragma warning(disable: 4237) // bool
  24. #pragma warning(disable: 4710) // function couldn't be inlined
  25. #pragma warning(disable: 4355) // 'this' : used in base member initializer list
  26. #pragma warning(disable: 4097) // typedef name used as synonym for class-name
  27. #pragma warning(disable: 4786) // identifier was truncated in the debug information
  28. #pragma warning(disable: 4268) // const static/global data initialized to zeros
  29. #pragma warning(disable: 4291) // allow placement new
  30. #endif //!_ATL_NO_PRAGMA_WARNINGS
  31. #include <atldef.h>
  32. #include <windows.h>
  33. #include <winnls.h>
  34. #include <ole2.h>
  35. #include <comcat.h>
  36. #include <stddef.h>
  37. #ifdef new
  38. #pragma push_macro("new")
  39. #define _ATL_REDEF_NEW
  40. #undef new
  41. #endif
  42. #include <tchar.h>
  43. #include <malloc.h>
  44. #ifndef _ATL_NO_DEBUG_CRT
  45. // Warning: if you define the above symbol, you will have
  46. // to provide your own definition of the ATLASSERT(x) macro
  47. // in order to compile ATL
  48. #include <crtdbg.h>
  49. #endif
  50. #include <olectl.h>
  51. #include <winreg.h>
  52. #include <atliface.h>
  53. #ifdef _DEBUG
  54. #include <stdio.h>
  55. #include <stdarg.h>
  56. #endif
  57. #include <atlconv.h>
  58. #include <shlwapi.h>
  59. #pragma pack(push, _ATL_PACKING)
  60. #if defined(_ATL_DLL)
  61. #pragma comment(lib, "atl.lib")
  62. #endif
  63. extern "C" const __declspec(selectany) GUID LIBID_ATLLib = {0x44EC0535,0x400F,0x11D0,{0x9D,0xCD,0x00,0xA0,0xC9,0x03,0x91,0xD3}};
  64. extern "C" const __declspec(selectany) CLSID CLSID_Registrar = {0x44EC053A,0x400F,0x11D0,{0x9D,0xCD,0x00,0xA0,0xC9,0x03,0x91,0xD3}};
  65. extern "C" const __declspec(selectany) IID IID_IRegistrar = {0x44EC053B,0x400F,0x11D0,{0x9D,0xCD,0x00,0xA0,0xC9,0x03,0x91,0xD3}};
  66. extern "C" const __declspec(selectany) IID IID_IAxWinHostWindow = {0xb6ea2050,0x48a,0x11d1,{0x82,0xb9,0x0,0xc0,0x4f,0xb9,0x94,0x2e}};
  67. extern "C" const __declspec(selectany) IID IID_IAxWinAmbientDispatch = {0xb6ea2051,0x48a,0x11d1,{0x82,0xb9,0x0,0xc0,0x4f,0xb9,0x94,0x2e}};
  68. extern "C" const __declspec(selectany) IID IID_IInternalConnection = {0x72AD0770,0x6A9F,0x11d1,{0xBC,0xEC,0x00,0x60,0x08,0x8F,0x44,0x4E}};
  69. extern "C" const __declspec(selectany) IID IID_IDocHostUIHandlerDispatch = {0x425B5AF0,0x65F1,0x11d1,{0x96,0x11,0x00,0x00,0xF8,0x1E,0x0D,0x0D}};
  70. #ifndef _ATL_DLL_IMPL
  71. namespace ATL
  72. {
  73. #endif
  74. struct _ATL_CATMAP_ENTRY
  75. {
  76. int iType;
  77. const CATID* pcatid;
  78. };
  79. #define _ATL_CATMAP_ENTRY_END 0
  80. #define _ATL_CATMAP_ENTRY_IMPLEMENTED 1
  81. #define _ATL_CATMAP_ENTRY_REQUIRED 2
  82. typedef HRESULT (WINAPI _ATL_CREATORFUNC)(void* pv, REFIID riid, LPVOID* ppv);
  83. typedef HRESULT (WINAPI _ATL_CREATORARGFUNC)(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw);
  84. typedef HRESULT (WINAPI _ATL_MODULEFUNC)(DWORD_PTR dw);
  85. typedef LPCTSTR (WINAPI _ATL_DESCRIPTIONFUNC)();
  86. typedef const struct _ATL_CATMAP_ENTRY* (_ATL_CATMAPFUNC)();
  87. typedef void (__stdcall _ATL_TERMFUNC)(DWORD_PTR dw);
  88. struct _ATL_TERMFUNC_ELEM
  89. {
  90. _ATL_TERMFUNC* pFunc;
  91. DWORD_PTR dw;
  92. _ATL_TERMFUNC_ELEM* pNext;
  93. };
  94. struct _ATL_OBJMAP_ENTRY
  95. {
  96. const CLSID* pclsid;
  97. HRESULT (WINAPI *pfnUpdateRegistry)(BOOL bRegister);
  98. _ATL_CREATORFUNC* pfnGetClassObject;
  99. _ATL_CREATORFUNC* pfnCreateInstance;
  100. IUnknown* pCF;
  101. DWORD dwRegister;
  102. _ATL_DESCRIPTIONFUNC* pfnGetObjectDescription;
  103. _ATL_CATMAPFUNC* pfnGetCategoryMap;
  104. HRESULT WINAPI RevokeClassObject()
  105. {
  106. return CoRevokeClassObject(dwRegister);
  107. }
  108. HRESULT WINAPI RegisterClassObject(DWORD dwClsContext, DWORD dwFlags)
  109. {
  110. IUnknown* p = NULL;
  111. if (pfnGetClassObject == NULL)
  112. return S_OK;
  113. HRESULT hRes = pfnGetClassObject(pfnCreateInstance, IID_IUnknown, (LPVOID*) &p);
  114. if (SUCCEEDED(hRes))
  115. hRes = CoRegisterClassObject(*pclsid, p, dwClsContext, dwFlags, &dwRegister);
  116. if (p != NULL)
  117. p->Release();
  118. return hRes;
  119. }
  120. // Added in ATL 3.0
  121. void (WINAPI *pfnObjectMain)(bool bStarting);
  122. };
  123. struct _ATL_REGMAP_ENTRY
  124. {
  125. LPCOLESTR szKey;
  126. LPCOLESTR szData;
  127. };
  128. struct _AtlCreateWndData
  129. {
  130. void* m_pThis;
  131. DWORD m_dwThreadID;
  132. _AtlCreateWndData* m_pNext;
  133. };
  134. struct _ATL_MODULE_21
  135. {
  136. // Attributes
  137. public:
  138. UINT cbSize;
  139. HINSTANCE m_hInst;
  140. HINSTANCE m_hInstResource;
  141. HINSTANCE m_hInstTypeLib;
  142. _ATL_OBJMAP_ENTRY* m_pObjMap;
  143. LONG m_nLockCnt;
  144. HANDLE m_hHeap;
  145. union
  146. {
  147. CRITICAL_SECTION m_csTypeInfoHolder;
  148. CRITICAL_SECTION m_csStaticDataInit;
  149. };
  150. CRITICAL_SECTION m_csWindowCreate;
  151. CRITICAL_SECTION m_csObjMap;
  152. };
  153. struct _ATL_MODULE_30
  154. {
  155. // Attributes
  156. public:
  157. UINT cbSize;
  158. HINSTANCE m_hInst;
  159. HINSTANCE m_hInstResource;
  160. HINSTANCE m_hInstTypeLib;
  161. _ATL_OBJMAP_ENTRY* m_pObjMap;
  162. LONG m_nLockCnt;
  163. HANDLE m_hHeap;
  164. union
  165. {
  166. CRITICAL_SECTION m_csTypeInfoHolder;
  167. CRITICAL_SECTION m_csStaticDataInit;
  168. };
  169. CRITICAL_SECTION m_csWindowCreate;
  170. CRITICAL_SECTION m_csObjMap;
  171. // Original Size = 100
  172. // Stuff added in ATL 3.0
  173. DWORD dwAtlBuildVer;
  174. _AtlCreateWndData* m_pCreateWndList;
  175. bool m_bDestroyHeap;
  176. GUID* pguidVer;
  177. DWORD m_dwHeaps; // Number of heaps we have (-1)
  178. HANDLE* m_phHeaps;
  179. int m_nHeap; // Which heap to choose from
  180. _ATL_TERMFUNC_ELEM* m_pTermFuncs;
  181. };
  182. struct _ATL_MODULE
  183. {
  184. // Attributes
  185. public:
  186. UINT cbSize;
  187. HINSTANCE m_hInst;
  188. HINSTANCE m_hInstResource;
  189. HINSTANCE m_hInstTypeLib;
  190. _ATL_OBJMAP_ENTRY* m_pObjMap;
  191. LONG m_nLockCnt;
  192. HANDLE m_hHeap;
  193. union
  194. {
  195. CRITICAL_SECTION m_csTypeInfoHolder;
  196. CRITICAL_SECTION m_csStaticDataInit;
  197. };
  198. CRITICAL_SECTION m_csWindowCreate;
  199. CRITICAL_SECTION m_csObjMap;
  200. // Original Size = 100
  201. // Stuff added in ATL 3.0
  202. DWORD dwAtlBuildVer;
  203. _AtlCreateWndData* m_pCreateWndList;
  204. bool m_bDestroyHeap;
  205. GUID* pguidVer;
  206. DWORD m_dwHeaps; // Number of heaps we have (-1)
  207. HANDLE* m_phHeaps;
  208. int m_nHeap; // Which heap to choose from
  209. _ATL_TERMFUNC_ELEM* m_pTermFuncs;
  210. // Stuff added in ATL 6.1
  211. LONG m_nNextWindowID;
  212. };
  213. const int _nAtlModuleVer21Size = sizeof( _ATL_MODULE_21 );
  214. const int _nAtlModuleVer30Size = sizeof( _ATL_MODULE_30 );
  215. //This define makes debugging asserts easier.
  216. #define _ATL_SIMPLEMAPENTRY ((_ATL_CREATORARGFUNC*)1)
  217. struct _ATL_INTMAP_ENTRY
  218. {
  219. const IID* piid; // the interface id (IID)
  220. DWORD_PTR dw;
  221. _ATL_CREATORARGFUNC* pFunc; //NULL:end, 1:offset, n:ptr
  222. };
  223. /////////////////////////////////////////////////////////////////////////////
  224. // Thunks for __stdcall member functions
  225. #if defined(_M_IX86)
  226. #pragma pack(push,1)
  227. struct _stdcallthunk
  228. {
  229. DWORD m_mov; // mov dword ptr [esp+0x4], pThis (esp+0x4 is hWnd)
  230. DWORD m_this; //
  231. BYTE m_jmp; // jmp WndProc
  232. DWORD m_relproc; // relative jmp
  233. void Init(DWORD_PTR proc, void* pThis)
  234. {
  235. m_mov = 0x042444C7; //C7 44 24 0C
  236. m_this = PtrToUlong(pThis);
  237. m_jmp = 0xe9;
  238. m_relproc = DWORD((INT_PTR)proc - ((INT_PTR)this+sizeof(_stdcallthunk)));
  239. // write block from data cache and
  240. // flush from instruction cache
  241. FlushInstructionCache(GetCurrentProcess(), this, sizeof(_stdcallthunk));
  242. }
  243. };
  244. #pragma pack(pop)
  245. #elif defined (_M_AMD64)
  246. #pragma pack(push,2)
  247. struct _stdcallthunk
  248. {
  249. USHORT RcxMov; // mov rcx, pThis
  250. ULONG64 RcxImm; //
  251. USHORT RaxMov; // mov rax, target
  252. ULONG64 RaxImm; //
  253. USHORT RaxJmp; // jmp target
  254. void Init(DWORD_PTR proc, void *pThis)
  255. {
  256. RcxMov = 0xb948; // mov rcx, pThis
  257. RcxImm = (ULONG64)pThis; //
  258. RaxMov = 0xb848; // mov rax, target
  259. RaxImm = (ULONG64)proc; //
  260. RaxJmp = 0xe0ff; // jmp rax
  261. FlushInstructionCache(GetCurrentProcess(), this, sizeof(_stdcallthunk));
  262. }
  263. };
  264. #pragma pack(pop)
  265. #elif defined(_M_IA64)
  266. #pragma pack(push,8)
  267. extern "C" LRESULT CALLBACK _WndProcThunkProc( HWND, UINT, WPARAM, LPARAM );
  268. struct _FuncDesc
  269. {
  270. void* pfn;
  271. void* gp;
  272. };
  273. struct _stdcallthunk
  274. {
  275. _FuncDesc m_funcdesc;
  276. void* m_pFunc;
  277. void* m_pThis;
  278. void Init(DWORD_PTR proc, void* pThis)
  279. {
  280. const _FuncDesc* pThunkProc;
  281. pThunkProc = reinterpret_cast< const _FuncDesc* >( _WndProcThunkProc );
  282. m_funcdesc.pfn = pThunkProc->pfn;
  283. m_funcdesc.gp = &m_pFunc;
  284. m_pFunc = reinterpret_cast< void* >( proc );
  285. m_pThis = pThis;
  286. ::FlushInstructionCache( GetCurrentProcess(), this, sizeof( _stdcallthunk ) );
  287. }
  288. };
  289. #pragma pack(pop)
  290. #else
  291. #error Only AMD64, IA64, and X86 supported
  292. #endif
  293. class CDynamicStdCallThunk
  294. {
  295. public:
  296. _stdcallthunk *pThunk;
  297. CDynamicStdCallThunk()
  298. {
  299. pThunk = NULL;
  300. }
  301. ~CDynamicStdCallThunk()
  302. {
  303. if (pThunk)
  304. HeapFree(GetProcessHeap(), 0, pThunk);
  305. }
  306. void Init(DWORD_PTR proc, void *pThis)
  307. {
  308. ATLASSERT(!pThunk);
  309. pThunk = static_cast<_stdcallthunk *>(HeapAlloc(GetProcessHeap(),
  310. HEAP_GENERATE_EXCEPTIONS, sizeof(_stdcallthunk)));
  311. ATLASSERT(pThunk);
  312. pThunk->Init(proc, pThis);
  313. }
  314. };
  315. typedef CDynamicStdCallThunk CStdCallThunk;
  316. /////////////////////////////////////////////////////////////////////////////
  317. // QI Support
  318. ATLAPI AtlInternalQueryInterface(void* pThis,
  319. const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, void** ppvObject);
  320. /////////////////////////////////////////////////////////////////////////////
  321. // Smart Pointer helpers
  322. ATLAPI_(IUnknown*) AtlComPtrAssign(IUnknown** pp, IUnknown* lp);
  323. ATLAPI_(IUnknown*) AtlComQIPtrAssign(IUnknown** pp, IUnknown* lp, REFIID riid);
  324. /////////////////////////////////////////////////////////////////////////////
  325. // Inproc Marshaling helpers
  326. ATLAPI AtlFreeMarshalStream(IStream* pStream);
  327. ATLAPI AtlMarshalPtrInProc(IUnknown* pUnk, const IID& iid, IStream** ppStream);
  328. ATLAPI AtlUnmarshalPtr(IStream* pStream, const IID& iid, IUnknown** ppUnk);
  329. ATLAPI_(BOOL) AtlWaitWithMessageLoop(HANDLE hEvent);
  330. /////////////////////////////////////////////////////////////////////////////
  331. // Connection Point Helpers
  332. ATLAPI AtlAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw);
  333. ATLAPI AtlUnadvise(IUnknown* pUnkCP, const IID& iid, DWORD dw);
  334. /////////////////////////////////////////////////////////////////////////////
  335. // IDispatch Error handling
  336. ATLAPI AtlSetErrorInfo(const CLSID& clsid, LPCOLESTR lpszDesc,
  337. DWORD dwHelpID, LPCOLESTR lpszHelpFile, const IID& iid, HRESULT hRes,
  338. HINSTANCE hInst);
  339. /////////////////////////////////////////////////////////////////////////////
  340. // Module
  341. ATLAPI AtlModuleRegisterClassObjects(_ATL_MODULE* pM, DWORD dwClsContext, DWORD dwFlags);
  342. ATLAPI AtlModuleRevokeClassObjects(_ATL_MODULE* pM);
  343. ATLAPI AtlModuleGetClassObject(_ATL_MODULE* pM, REFCLSID rclsid, REFIID riid, LPVOID* ppv);
  344. ATLAPI AtlModuleRegisterServer(_ATL_MODULE* pM, BOOL bRegTypeLib, const CLSID* pCLSID = NULL);
  345. ATLAPI AtlModuleUnregisterServer(_ATL_MODULE* pM, const CLSID* pCLSID = NULL);
  346. ATLAPI AtlModuleUnregisterServerEx(_ATL_MODULE* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID = NULL);
  347. ATLAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULE*pM, LPCOLESTR lpszRes,
  348. BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg = NULL);
  349. ATLAPI AtlModuleRegisterTypeLib(_ATL_MODULE* pM, LPCOLESTR lpszIndex);
  350. ATLAPI AtlModuleUnRegisterTypeLib(_ATL_MODULE* pM, LPCOLESTR lpszIndex);
  351. ATLAPI AtlModuleLoadTypeLib(_ATL_MODULE* pM, LPCOLESTR lpszIndex, BSTR* pbstrPath, ITypeLib** ppTypeLib);
  352. ATLAPI AtlModuleInit(_ATL_MODULE* pM, _ATL_OBJMAP_ENTRY* p, HINSTANCE h);
  353. ATLAPI AtlModuleTerm(_ATL_MODULE* pM);
  354. ATLAPI_(DWORD) AtlGetVersion(void* pReserved);
  355. ATLAPI_(void) AtlModuleAddCreateWndData(_ATL_MODULE* pM, _AtlCreateWndData* pData, void* pObject);
  356. ATLAPI_(void*) AtlModuleExtractCreateWndData(_ATL_MODULE* pM);
  357. ATLAPI AtlModuleAddTermFunc(_ATL_MODULE* pM, _ATL_TERMFUNC* pFunc, DWORD_PTR dw);
  358. #ifndef _ATL_DLL_IMPL
  359. }; //namespace ATL
  360. #endif
  361. namespace ATL
  362. {
  363. /////////////////////////////////////////////////////////////////////////////
  364. // Error to HRESULT helpers
  365. inline HRESULT AtlHresultFromLastError()
  366. {
  367. DWORD dwErr = ::GetLastError();
  368. return HRESULT_FROM_WIN32(dwErr);
  369. }
  370. inline HRESULT AtlHresultFromWin32(DWORD nError)
  371. {
  372. return( HRESULT_FROM_WIN32( nError ) );
  373. }
  374. enum atlTraceFlags
  375. {
  376. // Application defined categories
  377. atlTraceUser = 0x00000001,
  378. atlTraceUser2 = 0x00000002,
  379. atlTraceUser3 = 0x00000004,
  380. atlTraceUser4 = 0x00000008,
  381. // ATL defined categories
  382. atlTraceGeneral = 0x00000020,
  383. atlTraceCOM = 0x00000040,
  384. atlTraceQI = 0x00000080,
  385. atlTraceRegistrar = 0x00000100,
  386. atlTraceRefcount = 0x00000200,
  387. atlTraceWindowing = 0x00000400,
  388. atlTraceControls = 0x00000800,
  389. atlTraceHosting = 0x00001000,
  390. atlTraceDBClient = 0x00002000,
  391. atlTraceDBProvider = 0x00004000,
  392. atlTraceSnapin = 0x00008000,
  393. atlTraceNotImpl = 0x00010000,
  394. };
  395. #ifndef ATL_TRACE_CATEGORY
  396. #define ATL_TRACE_CATEGORY 0xFFFFFFFF
  397. #endif
  398. #ifdef _DEBUG
  399. #ifndef ATL_TRACE_LEVEL
  400. #define ATL_TRACE_LEVEL 0
  401. #endif
  402. inline void _cdecl AtlTrace(LPCSTR lpszFormat, ...)
  403. {
  404. va_list args;
  405. va_start(args, lpszFormat);
  406. int nBuf;
  407. char szBuffer[512];
  408. nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);
  409. ATLASSERT(nBuf < sizeof(szBuffer)); //Output truncated as it was > sizeof(szBuffer)
  410. OutputDebugStringA(szBuffer);
  411. va_end(args);
  412. }
  413. inline void _cdecl AtlTrace2(DWORD category, UINT level, LPCSTR lpszFormat, ...)
  414. {
  415. if (category & ATL_TRACE_CATEGORY && level <= ATL_TRACE_LEVEL)
  416. {
  417. va_list args;
  418. va_start(args, lpszFormat);
  419. int nBuf;
  420. char szBuffer[512];
  421. nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);
  422. ATLASSERT(nBuf < sizeof(szBuffer)); //Output truncated as it was > sizeof(szBuffer)
  423. OutputDebugStringA("ATL: ");
  424. OutputDebugStringA(szBuffer);
  425. va_end(args);
  426. }
  427. }
  428. #ifndef OLE2ANSI
  429. inline void _cdecl AtlTrace(LPCWSTR lpszFormat, ...)
  430. {
  431. va_list args;
  432. va_start(args, lpszFormat);
  433. int nBuf;
  434. WCHAR szBuffer[512];
  435. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer) / sizeof(WCHAR), lpszFormat, args);
  436. ATLASSERT(nBuf < sizeof(szBuffer));//Output truncated as it was > sizeof(szBuffer)
  437. OutputDebugStringW(szBuffer);
  438. va_end(args);
  439. }
  440. inline void _cdecl AtlTrace2(DWORD category, UINT level, LPCWSTR lpszFormat, ...)
  441. {
  442. if (category & ATL_TRACE_CATEGORY && level <= ATL_TRACE_LEVEL)
  443. {
  444. va_list args;
  445. va_start(args, lpszFormat);
  446. int nBuf;
  447. WCHAR szBuffer[512];
  448. nBuf = _vsnwprintf(szBuffer, sizeof(szBuffer) / sizeof(WCHAR), lpszFormat, args);
  449. ATLASSERT(nBuf < sizeof(szBuffer));//Output truncated as it was > sizeof(szBuffer)
  450. OutputDebugStringW(L"ATL: ");
  451. OutputDebugStringW(szBuffer);
  452. va_end(args);
  453. }
  454. }
  455. #endif //!OLE2ANSI
  456. #ifndef ATLTRACE
  457. #define ATLTRACE AtlTrace
  458. #define ATLTRACE2 AtlTrace2
  459. #endif
  460. #define ATLTRACENOTIMPL(funcname) ATLTRACE2(atlTraceNotImpl, 2, _T("ATL: %s not implemented.\n"), funcname); return E_NOTIMPL
  461. #else // !DEBUG
  462. inline void _cdecl AtlTrace(LPCSTR , ...){}
  463. inline void _cdecl AtlTrace2(DWORD, UINT, LPCSTR , ...){}
  464. #ifndef OLE2ANSI
  465. inline void _cdecl AtlTrace(LPCWSTR , ...){}
  466. inline void _cdecl AtlTrace2(DWORD, UINT, LPCWSTR , ...){}
  467. #endif //OLE2ANSI
  468. #ifndef ATLTRACE
  469. #define ATLTRACE 1 ? (void)0 : AtlTrace
  470. #define ATLTRACE2 1 ? (void)0 : AtlTrace2
  471. #endif //ATLTRACE
  472. #define ATLTRACENOTIMPL(funcname) return E_NOTIMPL
  473. #endif //_DEBUG
  474. // Validation macro for OUT pointer
  475. // Used in QI and CreateInstance
  476. #define _ATL_VALIDATE_OUT_POINTER(x) ATLASSERT(x != NULL); \
  477. if (x == NULL) \
  478. return E_POINTER; \
  479. *x = NULL
  480. /////////////////////////////////////////////////////////////////////////////
  481. // Win32 libraries
  482. #pragma comment(lib, "kernel32.lib")
  483. #pragma comment(lib, "user32.lib")
  484. #ifndef _WIN64
  485. #pragma comment(lib, "olepro32.lib")
  486. #endif
  487. #pragma comment(lib, "advapi32.lib")
  488. #pragma comment(lib, "ole32.lib")
  489. #pragma comment(lib, "oleaut32.lib")
  490. #pragma comment(lib, "uuid.lib")
  491. template <class Ty> class stl_smart_ptr_allocator {
  492. public:
  493. typedef size_t size_type;
  494. typedef ptrdiff_t difference_type;
  495. typedef Ty *pointer;
  496. typedef const Ty *const_pointer;
  497. typedef Ty & reference;
  498. typedef const Ty & const_reference;
  499. typedef Ty value_type;
  500. pointer address(reference _X) const
  501. {return ((_X.address)()); }
  502. const_pointer address(const_reference _X) const
  503. {return ((_X.const_address)()); }
  504. pointer allocate(ptrdiff_t _N, const void *)
  505. {if (_N < 0)
  506. _N = 0;
  507. return ((pointer)operator new(
  508. (size_type)_N * sizeof (Ty))); }
  509. char *_Charalloc(ptrdiff_t _N)
  510. {if (_N < 0)
  511. _N = 0;
  512. return ((char *)operator new(
  513. (size_type)_N * sizeof (char))); }
  514. void deallocate(void *_P, size_type)
  515. {operator delete(_P); }
  516. void construct(pointer _P, const Ty& _V)
  517. {new ((void *)_P) Ty(_V); }
  518. // note: there is an stl bug regarding allocators and the list container
  519. // (vc6 list line 222) the template takes the address of the object
  520. // which breaks for smart pointers because the & is overloaded.
  521. // the correct thing is for construct to be defined as a reference
  522. // and list not use & so that the allocator can use a private method
  523. // of obtaining the object address
  524. // i've gone ahead and defined the correct method here on the remote
  525. // chance that this will get fixed in the future
  526. void construct(reference R, const Ty& _V)
  527. {new ((void *)R.address()) Ty(_V); }
  528. void destroy(pointer _P)
  529. {_Destroy(_P); }
  530. size_type max_size() const
  531. {size_type _N = (size_type)(-1) / sizeof (Ty);
  532. return (0 < _N ? _N : 1); }
  533. inline void _Destroy(Ty *_P)
  534. {(_P)->~Ty();}
  535. inline void _Destroy(char *_P)
  536. {}
  537. inline void _Destroy(wchar_t *_P)
  538. {}
  539. };
  540. static HRESULT AtlSetChildSite(IUnknown* punkChild, IUnknown* punkParent)
  541. {
  542. if (punkChild == NULL)
  543. return E_POINTER;
  544. HRESULT hr;
  545. IObjectWithSite* pChildSite = NULL;
  546. hr = punkChild->QueryInterface(IID_IObjectWithSite, (void**)&pChildSite);
  547. if (SUCCEEDED(hr) && pChildSite != NULL)
  548. {
  549. hr = pChildSite->SetSite(punkParent);
  550. pChildSite->Release();
  551. }
  552. return hr;
  553. }
  554. template <class T>
  555. class _NoAddRefReleaseOnCComPtr : public T
  556. {
  557. private:
  558. STDMETHOD_(ULONG, AddRef)()=0;
  559. STDMETHOD_(ULONG, Release)()=0;
  560. };
  561. template <class T>
  562. class CComPtr
  563. {
  564. public:
  565. typedef T _PtrClass;
  566. CComPtr()
  567. {
  568. p=NULL;
  569. }
  570. CComPtr(T* lp)
  571. {
  572. if ((p = lp) != NULL)
  573. p->AddRef();
  574. }
  575. CComPtr(const CComPtr<T>& lp)
  576. {
  577. if ((p = lp.p) != NULL)
  578. p->AddRef();
  579. }
  580. CComPtr(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  581. : p(NULL)
  582. {
  583. ATLASSERT(p == NULL);
  584. HRESULT hr = ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  585. if (FAILED(hr)) ATLASSERT(p == NULL);
  586. }
  587. CComPtr(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  588. : p(NULL)
  589. {
  590. CLSID clsid;
  591. HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  592. ATLASSERT(p == NULL);
  593. if (SUCCEEDED(hr))
  594. hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  595. if (FAILED(hr)) ATLASSERT(p == NULL);
  596. }
  597. ~CComPtr()
  598. {
  599. if (p)
  600. p->Release();
  601. }
  602. void Release()
  603. {
  604. IUnknown* pTemp = p;
  605. if (pTemp)
  606. {
  607. p = NULL;
  608. pTemp->Release();
  609. }
  610. }
  611. operator T*() const
  612. {
  613. return (T*)p;
  614. }
  615. T& operator*() const
  616. {
  617. ATLASSERT(p!=NULL);
  618. return *p;
  619. }
  620. //The assert on operator& usually indicates a bug. If this is really
  621. //what is needed, however, take the address of the p member explicitly.
  622. T** operator&()
  623. {
  624. ATLASSERT(p==NULL);
  625. return &p;
  626. }
  627. _NoAddRefReleaseOnCComPtr<T>* operator->() const
  628. {
  629. ATLASSERT(p!=NULL);
  630. return (_NoAddRefReleaseOnCComPtr<T>*)p;
  631. }
  632. T* operator=(T* lp)
  633. {
  634. return (T*)AtlComPtrAssign((IUnknown**)&p, lp);
  635. }
  636. T* operator=(const CComPtr<T>& lp)
  637. {
  638. return (T*)AtlComPtrAssign((IUnknown**)&p, lp.p);
  639. }
  640. bool operator!() const
  641. {
  642. return (p == NULL);
  643. }
  644. bool operator<(T* pT) const
  645. {
  646. return p < pT;
  647. }
  648. bool operator==(T* pT) const
  649. {
  650. return p == pT;
  651. }
  652. // Compare two objects for equivalence
  653. bool IsEqualObject(IUnknown* pOther)
  654. {
  655. if (p == NULL && pOther == NULL)
  656. return true; // They are both NULL objects
  657. if (p == NULL || pOther == NULL)
  658. return false; // One is NULL the other is not
  659. CComPtr<IUnknown> punk1;
  660. CComPtr<IUnknown> punk2;
  661. p->QueryInterface(IID_IUnknown, (void**)&punk1);
  662. pOther->QueryInterface(IID_IUnknown, (void**)&punk2);
  663. return punk1 == punk2;
  664. }
  665. void Attach(T* p2)
  666. {
  667. if (p)
  668. p->Release();
  669. p = p2;
  670. }
  671. T* Detach()
  672. {
  673. T* pt = p;
  674. p = NULL;
  675. return pt;
  676. }
  677. #if 0
  678. HRESULT CopyTo(T** ppT)
  679. {
  680. // there should either be a runtime check or an assert(not both). otherwise
  681. // we can't depend on the runtime check during unattended api tests and have to
  682. // place a redundant extra check outside the call to CopyTo to keep assert
  683. // dialogs from popping up
  684. // ATLASSERT(ppT != NULL);
  685. if (ppT == NULL)
  686. return E_POINTER;
  687. *ppT = p;
  688. if (p)
  689. p->AddRef();
  690. return S_OK;
  691. }
  692. #else
  693. // we want to enable CopyTo to work correctly with bases of T
  694. // if INTERFACE isn't a base then we'll get a compile error
  695. template<class INTERFACE> HRESULT CopyTo(INTERFACE** ppT)
  696. {
  697. // there should either be a runtime check or an assert(not both). otherwise
  698. // we can't depend on the runtime check during unattended api tests and have to
  699. // place a redundant extra check outside the call to CopyTo to keep assert
  700. // dialogs from popping up
  701. // ATLASSERT(ppT != NULL);
  702. if (ppT == NULL)
  703. return E_POINTER;
  704. *ppT = p;
  705. if (p)
  706. p->AddRef();
  707. return S_OK;
  708. }
  709. #endif
  710. HRESULT SetSite(IUnknown* punkParent)
  711. {
  712. return AtlSetChildSite(p, punkParent);
  713. }
  714. HRESULT Advise(IUnknown* pUnk, const IID& iid, LPDWORD pdw)
  715. {
  716. return AtlAdvise(p, pUnk, iid, pdw);
  717. }
  718. HRESULT CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  719. {
  720. ATLASSERT(p == NULL);
  721. return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  722. }
  723. HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  724. {
  725. CLSID clsid;
  726. HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  727. ATLASSERT(p == NULL);
  728. if (SUCCEEDED(hr))
  729. hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  730. return hr;
  731. }
  732. template <class Q>
  733. HRESULT QueryInterface(Q** pp) const
  734. {
  735. ATLASSERT(pp != NULL && *pp == NULL);
  736. return p->QueryInterface(__uuidof(Q), (void**)pp);
  737. }
  738. // this allows direct use in stl containers
  739. // without using the CAdapt template which causes extra addrefs/releases
  740. // usage:
  741. // std::vector<CComPtr<IMytype>, CComPtr<IMytype>::stl_allocator>
  742. CComPtr<T> * address(void) { return this; }
  743. const CComPtr<T> * const_address(void) const { return this; }
  744. typedef stl_smart_ptr_allocator<CComPtr<T> > stl_allocator;
  745. T* p;
  746. };
  747. template <class T, const IID* piid = &__uuidof(T)>
  748. class CComQIPtr
  749. {
  750. public:
  751. typedef T _PtrClass;
  752. CComQIPtr()
  753. {
  754. p=NULL;
  755. }
  756. CComQIPtr(T* lp)
  757. {
  758. if ((p = lp) != NULL)
  759. p->AddRef();
  760. }
  761. CComQIPtr(const CComQIPtr<T,piid>& lp)
  762. {
  763. if ((p = lp.p) != NULL)
  764. p->AddRef();
  765. }
  766. CComQIPtr(IUnknown* lp)
  767. {
  768. p=NULL;
  769. if (lp != NULL)
  770. lp->QueryInterface(*piid, (void **)&p);
  771. }
  772. CComQIPtr(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  773. : p(NULL)
  774. {
  775. ATLASSERT(p == NULL);
  776. HRESULT hr = ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  777. if (FAILED(hr)) ATLASSERT(p == NULL);
  778. }
  779. CComQIPtr(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  780. : p(NULL)
  781. {
  782. CLSID clsid;
  783. HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  784. ATLASSERT(p == NULL);
  785. if (SUCCEEDED(hr))
  786. hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  787. if (FAILED(hr)) ATLASSERT(p == NULL);
  788. }
  789. ~CComQIPtr()
  790. {
  791. if (p)
  792. p->Release();
  793. }
  794. void Release()
  795. {
  796. IUnknown* pTemp = p;
  797. if (pTemp)
  798. {
  799. p = NULL;
  800. pTemp->Release();
  801. }
  802. }
  803. operator T*() const
  804. {
  805. return p;
  806. }
  807. T& operator*() const
  808. {
  809. ATLASSERT(p!=NULL); return *p;
  810. }
  811. //The assert on operator& usually indicates a bug. If this is really
  812. //what is needed, however, take the address of the p member explicitly.
  813. T** operator&()
  814. {
  815. // this is unavoidably triggered by legitimate access inside templates. example:
  816. // using a CComQIPtr in an stl container and then using IEnumonSTLImpl the ::Next
  817. // method contains a Copy::copy operation that causes this problem.
  818. // ATLASSERT(p==NULL);
  819. return &p;
  820. }
  821. _NoAddRefReleaseOnCComPtr<T>* operator->() const
  822. {
  823. ATLASSERT(p!=NULL);
  824. return (_NoAddRefReleaseOnCComPtr<T>*)p;
  825. }
  826. T* operator=(T* lp)
  827. {
  828. return (T*)AtlComPtrAssign((IUnknown**)&p, lp);
  829. }
  830. T* operator=(const CComQIPtr<T,piid>& lp)
  831. {
  832. return (T*)AtlComPtrAssign((IUnknown**)&p, lp.p);
  833. }
  834. T* operator=(IUnknown* lp)
  835. {
  836. return (T*)AtlComQIPtrAssign((IUnknown**)&p, lp, *piid);
  837. }
  838. bool operator!() const
  839. {
  840. return (p == NULL);
  841. }
  842. bool operator<(T* pT) const
  843. {
  844. return p < pT;
  845. }
  846. bool operator==(T* pT) const
  847. {
  848. return p == pT;
  849. }
  850. // Compare two objects for equivalence
  851. bool IsEqualObject(IUnknown* pOther)
  852. {
  853. if (p == NULL && pOther == NULL)
  854. return true; // They are both NULL objects
  855. if (p == NULL || pOther == NULL)
  856. return false; // One is NULL the other is not
  857. CComPtr<IUnknown> punk1;
  858. CComPtr<IUnknown> punk2;
  859. p->QueryInterface(IID_IUnknown, (void**)&punk1);
  860. pOther->QueryInterface(IID_IUnknown, (void**)&punk2);
  861. return punk1 == punk2;
  862. }
  863. void Attach(T* p2)
  864. {
  865. if (p)
  866. p->Release();
  867. p = p2;
  868. }
  869. T* Detach()
  870. {
  871. T* pt = p;
  872. p = NULL;
  873. return pt;
  874. }
  875. #if 0
  876. HRESULT CopyTo(T** ppT)
  877. {
  878. // there should either be a runtime check or an assert(not both). otherwise
  879. // we can't depend on the runtime check during unattended api tests and have to
  880. // place a redundant extra check outside the call to CopyTo to keep assert
  881. // dialogs from popping up
  882. // ATLASSERT(ppT != NULL);
  883. if (ppT == NULL)
  884. return E_POINTER;
  885. *ppT = p;
  886. if (p)
  887. p->AddRef();
  888. return S_OK;
  889. }
  890. #else
  891. // we want to enable CopyTo to work correctly with bases of T
  892. // if INTERFACE isn't a base then we'll get a compile error
  893. template<class INTERFACE> HRESULT CopyTo(INTERFACE** ppT)
  894. {
  895. // there should either be a runtime check or an assert(not both). otherwise
  896. // we can't depend on the runtime check during unattended api tests and have to
  897. // place a redundant extra check outside the call to CopyTo to keep assert
  898. // dialogs from popping up
  899. // ATLASSERT(ppT != NULL);
  900. if (ppT == NULL)
  901. return E_POINTER;
  902. *ppT = p;
  903. if (p)
  904. p->AddRef();
  905. return S_OK;
  906. }
  907. #endif
  908. HRESULT SetSite(IUnknown* punkParent)
  909. {
  910. return AtlSetChildSite(p, punkParent);
  911. }
  912. HRESULT Advise(IUnknown* pUnk, const IID& iid, LPDWORD pdw)
  913. {
  914. return AtlAdvise(p, pUnk, iid, pdw);
  915. }
  916. HRESULT CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  917. {
  918. ATLASSERT(p == NULL);
  919. return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  920. }
  921. HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  922. {
  923. CLSID clsid;
  924. HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  925. ATLASSERT(p == NULL);
  926. if (SUCCEEDED(hr))
  927. hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p);
  928. return hr;
  929. }
  930. template <class Q>
  931. HRESULT QueryInterface(Q** pp)
  932. {
  933. ATLASSERT(pp != NULL && *pp == NULL);
  934. return p->QueryInterface(__uuidof(Q), (void**)pp);
  935. }
  936. // this allows direct use in stl containers
  937. // without using the CAdapt template which causes extra addrefs/releases
  938. // usage:
  939. // std::vector<CComQIPtr<IMytype>, CComQIPtr<IMytype>::stl_allocator>
  940. CComQIPtr<T,piid> * address(void) { return this; }
  941. const CComQIPtr<T,piid> * const_address(void) const { return this; }
  942. typedef stl_smart_ptr_allocator<CComQIPtr<T, piid> > stl_allocator;
  943. T* p;
  944. };
  945. //Specialization to make it work
  946. template<>
  947. class CComQIPtr<IUnknown, &IID_IUnknown>
  948. {
  949. public:
  950. typedef IUnknown _PtrClass;
  951. CComQIPtr()
  952. {
  953. p=NULL;
  954. }
  955. CComQIPtr(IUnknown* lp)
  956. {
  957. //Actually do a QI to get identity
  958. p=NULL;
  959. if (lp != NULL)
  960. lp->QueryInterface(IID_IUnknown, (void **)&p);
  961. }
  962. CComQIPtr(const CComQIPtr<IUnknown,&IID_IUnknown>& lp)
  963. {
  964. if ((p = lp.p) != NULL)
  965. p->AddRef();
  966. }
  967. CComQIPtr(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  968. : p(NULL)
  969. {
  970. ATLASSERT(p == NULL);
  971. HRESULT hr = ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(IUnknown), (void**)&p);
  972. if (FAILED(hr)) ATLASSERT(p == NULL);
  973. }
  974. CComQIPtr(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  975. : p(NULL)
  976. {
  977. CLSID clsid;
  978. HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  979. ATLASSERT(p == NULL);
  980. if (SUCCEEDED(hr))
  981. hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(IUnknown), (void**)&p);
  982. if (FAILED(hr)) ATLASSERT(p == NULL);
  983. }
  984. ~CComQIPtr()
  985. {
  986. if (p)
  987. p->Release();
  988. }
  989. void Release()
  990. {
  991. IUnknown* pTemp = p;
  992. if (pTemp)
  993. {
  994. p = NULL;
  995. pTemp->Release();
  996. }
  997. }
  998. operator IUnknown*() const
  999. {
  1000. return p;
  1001. }
  1002. IUnknown& operator*() const
  1003. {
  1004. ATLASSERT(p!=NULL);
  1005. return *p;
  1006. }
  1007. //The assert on operator& usually indicates a bug. If this is really
  1008. //what is needed, however, take the address of the p member explicitly.
  1009. IUnknown** operator&()
  1010. {
  1011. ATLASSERT(p==NULL);
  1012. return &p;
  1013. }
  1014. _NoAddRefReleaseOnCComPtr<IUnknown>* operator->() const
  1015. {
  1016. ATLASSERT(p!=NULL);
  1017. return (_NoAddRefReleaseOnCComPtr<IUnknown>*)p;
  1018. }
  1019. IUnknown* operator=(IUnknown* lp)
  1020. {
  1021. //Actually do a QI to get identity
  1022. return (IUnknown*)AtlComQIPtrAssign((IUnknown**)&p, lp, IID_IUnknown);
  1023. }
  1024. IUnknown* operator=(const CComQIPtr<IUnknown,&IID_IUnknown>& lp)
  1025. {
  1026. return (IUnknown*)AtlComPtrAssign((IUnknown**)&p, lp.p);
  1027. }
  1028. bool operator!() const
  1029. {
  1030. return (p == NULL);
  1031. }
  1032. bool operator<(IUnknown* pT) const
  1033. {
  1034. return p < pT;
  1035. }
  1036. bool operator==(IUnknown* pT) const
  1037. {
  1038. return p == pT;
  1039. }
  1040. // Compare two objects for equivalence
  1041. bool IsEqualObject(IUnknown* pOther)
  1042. {
  1043. if (p == NULL && pOther == NULL)
  1044. return true; // They are both NULL objects
  1045. if (p == NULL || pOther == NULL)
  1046. return false; // One is NULL the other is not
  1047. CComPtr<IUnknown> punk1;
  1048. CComPtr<IUnknown> punk2;
  1049. p->QueryInterface(IID_IUnknown, (void**)&punk1);
  1050. pOther->QueryInterface(IID_IUnknown, (void**)&punk2);
  1051. return punk1 == punk2;
  1052. }
  1053. IUnknown* Detach()
  1054. {
  1055. IUnknown* pt = p;
  1056. p = NULL;
  1057. return pt;
  1058. }
  1059. HRESULT CopyTo(IUnknown** ppT)
  1060. {
  1061. // there should either be a runtime check or an assert(not both). otherwise
  1062. // we can't depend on the runtime check during unattended api tests and have to
  1063. // place a redundant extra check outside the call to CopyTo to keep assert
  1064. // dialogs from popping up
  1065. //ATLASSERT(ppT != NULL);
  1066. if (ppT == NULL)
  1067. return E_POINTER;
  1068. *ppT = p;
  1069. if (p)
  1070. p->AddRef();
  1071. return S_OK;
  1072. }
  1073. HRESULT SetSite(IUnknown* punkParent)
  1074. {
  1075. return AtlSetChildSite(p, punkParent);
  1076. }
  1077. HRESULT Advise(IUnknown* pUnk, const IID& iid, LPDWORD pdw)
  1078. {
  1079. return AtlAdvise(p, pUnk, iid, pdw);
  1080. }
  1081. HRESULT CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  1082. {
  1083. ATLASSERT(p == NULL);
  1084. return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(IUnknown), (void**)&p);
  1085. }
  1086. HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
  1087. {
  1088. CLSID clsid;
  1089. HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
  1090. ATLASSERT(p == NULL);
  1091. if (SUCCEEDED(hr))
  1092. hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(IUnknown), (void**)&p);
  1093. return hr;
  1094. }
  1095. template <class Q>
  1096. HRESULT QueryInterface(Q** pp)
  1097. {
  1098. ATLASSERT(pp != NULL && *pp == NULL);
  1099. return p->QueryInterface(__uuidof(Q), (void**)pp);
  1100. }
  1101. // this allows direct use in stl containers
  1102. // without using the CAdapt template which causes extra addrefs/releases
  1103. // usage:
  1104. // std::vector<CComPtr<IMytype>, CComPtr<IMytype>::stl_allocator>
  1105. CComQIPtr<IUnknown, &IID_IUnknown> * address(void) { return this; }
  1106. const CComQIPtr<IUnknown, &IID_IUnknown> * const_address(void) const { return this; }
  1107. typedef stl_smart_ptr_allocator<CComQIPtr<IUnknown, &IID_IUnknown> > stl_allocator;
  1108. IUnknown* p;
  1109. };
  1110. #define com_cast CComQIPtr
  1111. #if 0
  1112. /////////////////////////////////////////////////////////////
  1113. // Class to Adapt CComBSTR and CComPtr for use with STL containers
  1114. // the syntax to use it is
  1115. // std::vector< CAdapt <CComBSTR> > vect;
  1116. template <class T>
  1117. class CAdapt
  1118. {
  1119. public:
  1120. CAdapt()
  1121. {
  1122. }
  1123. CAdapt(const T& rSrc)
  1124. {
  1125. m_T = rSrc;
  1126. }
  1127. CAdapt(const CAdapt& rSrCA)
  1128. {
  1129. m_T = rSrCA.m_T;
  1130. }
  1131. CAdapt& operator=(const T& rSrc)
  1132. {
  1133. m_T = rSrc;
  1134. return *this;
  1135. }
  1136. bool operator<(const T& rSrc) const
  1137. {
  1138. return m_T < rSrc;
  1139. }
  1140. bool operator==(const T& rSrc) const
  1141. {
  1142. return m_T == rSrc;
  1143. }
  1144. operator T&()
  1145. {
  1146. return m_T;
  1147. }
  1148. operator const T&() const
  1149. {
  1150. return m_T;
  1151. }
  1152. T m_T;
  1153. };
  1154. #endif
  1155. /////////////////////////////////////////////////////////////////////////////
  1156. // GUID comparison
  1157. #ifndef _SYS_GUID_OPERATORS_
  1158. inline BOOL InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2)
  1159. {
  1160. return (
  1161. ((PLONG) &rguid1)[0] == ((PLONG) &rguid2)[0] &&
  1162. ((PLONG) &rguid1)[1] == ((PLONG) &rguid2)[1] &&
  1163. ((PLONG) &rguid1)[2] == ((PLONG) &rguid2)[2] &&
  1164. ((PLONG) &rguid1)[3] == ((PLONG) &rguid2)[3]);
  1165. }
  1166. #endif
  1167. inline BOOL InlineIsEqualUnknown(REFGUID rguid1)
  1168. {
  1169. return (
  1170. ((PLONG) &rguid1)[0] == 0 &&
  1171. ((PLONG) &rguid1)[1] == 0 &&
  1172. #ifdef _ATL_BYTESWAP
  1173. ((PLONG) &rguid1)[2] == 0xC0000000 &&
  1174. ((PLONG) &rguid1)[3] == 0x00000046);
  1175. #else
  1176. ((PLONG) &rguid1)[2] == 0x000000C0 &&
  1177. ((PLONG) &rguid1)[3] == 0x46000000);
  1178. #endif
  1179. }
  1180. /////////////////////////////////////////////////////////////////////////////
  1181. // Threading Model Support
  1182. class CComCriticalSection
  1183. {
  1184. public:
  1185. void Lock() {EnterCriticalSection(&m_sec);}
  1186. void Unlock() {LeaveCriticalSection(&m_sec);}
  1187. void Init() {InitializeCriticalSection(&m_sec);}
  1188. void Term() {DeleteCriticalSection(&m_sec);}
  1189. CRITICAL_SECTION m_sec;
  1190. };
  1191. class CComAutoCriticalSection
  1192. {
  1193. public:
  1194. void Lock() {EnterCriticalSection(&m_sec);}
  1195. void Unlock() {LeaveCriticalSection(&m_sec);}
  1196. CComAutoCriticalSection() {InitializeCriticalSection(&m_sec);}
  1197. ~CComAutoCriticalSection() {DeleteCriticalSection(&m_sec);}
  1198. CRITICAL_SECTION m_sec;
  1199. };
  1200. class CComFakeCriticalSection
  1201. {
  1202. public:
  1203. void Lock() {}
  1204. void Unlock() {}
  1205. void Init() {}
  1206. void Term() {}
  1207. };
  1208. class CComMultiThreadModelNoCS
  1209. {
  1210. public:
  1211. static ULONG WINAPI Increment(LPLONG p) {return InterlockedIncrement(p);}
  1212. static ULONG WINAPI Decrement(LPLONG p) {return InterlockedDecrement(p);}
  1213. typedef CComFakeCriticalSection AutoCriticalSection;
  1214. typedef CComFakeCriticalSection CriticalSection;
  1215. typedef CComMultiThreadModelNoCS ThreadModelNoCS;
  1216. };
  1217. class CComMultiThreadModel
  1218. {
  1219. public:
  1220. static ULONG WINAPI Increment(LPLONG p) {return InterlockedIncrement(p);}
  1221. static ULONG WINAPI Decrement(LPLONG p) {return InterlockedDecrement(p);}
  1222. typedef CComAutoCriticalSection AutoCriticalSection;
  1223. typedef CComCriticalSection CriticalSection;
  1224. typedef CComMultiThreadModelNoCS ThreadModelNoCS;
  1225. };
  1226. class CComSingleThreadModel
  1227. {
  1228. public:
  1229. static ULONG WINAPI Increment(LPLONG p) {return ++(*p);}
  1230. static ULONG WINAPI Decrement(LPLONG p) {return --(*p);}
  1231. typedef CComFakeCriticalSection AutoCriticalSection;
  1232. typedef CComFakeCriticalSection CriticalSection;
  1233. typedef CComSingleThreadModel ThreadModelNoCS;
  1234. };
  1235. #if defined(_ATL_SINGLE_THREADED)
  1236. typedef CComSingleThreadModel CComObjectThreadModel;
  1237. typedef CComSingleThreadModel CComGlobalsThreadModel;
  1238. #elif defined(_ATL_APARTMENT_THREADED)
  1239. typedef CComSingleThreadModel CComObjectThreadModel;
  1240. typedef CComMultiThreadModel CComGlobalsThreadModel;
  1241. #else
  1242. typedef CComMultiThreadModel CComObjectThreadModel;
  1243. typedef CComMultiThreadModel CComGlobalsThreadModel;
  1244. #endif
  1245. /////////////////////////////////////////////////////////////////////////////
  1246. // CComModule
  1247. #define THREADFLAGS_APARTMENT 0x1
  1248. #define THREADFLAGS_BOTH 0x2
  1249. #define AUTPRXFLAG 0x4
  1250. HRESULT WINAPI AtlDumpIID(REFIID iid, LPCTSTR pszClassName, HRESULT hr);
  1251. #ifdef _ATL_DEBUG_INTERFACES
  1252. struct _QIThunk
  1253. {
  1254. STDMETHOD(QueryInterface)(REFIID iid, void** pp)
  1255. {
  1256. ATLASSERT(m_dwRef >= 0);
  1257. return pUnk->QueryInterface(iid, pp);
  1258. }
  1259. STDMETHOD_(ULONG, AddRef)()
  1260. {
  1261. if (bBreak)
  1262. DebugBreak();
  1263. pUnk->AddRef();
  1264. return InternalAddRef();
  1265. }
  1266. ULONG InternalAddRef()
  1267. {
  1268. if (bBreak)
  1269. DebugBreak();
  1270. ATLASSERT(m_dwRef >= 0);
  1271. long l = InterlockedIncrement(&m_dwRef);
  1272. ATLTRACE(_T("%d> "), m_dwRef);
  1273. AtlDumpIID(iid, lpszClassName, S_OK);
  1274. if (l > m_dwMaxRef)
  1275. m_dwMaxRef = l;
  1276. return l;
  1277. }
  1278. STDMETHOD_(ULONG, Release)();
  1279. STDMETHOD(f3)();
  1280. STDMETHOD(f4)();
  1281. STDMETHOD(f5)();
  1282. STDMETHOD(f6)();
  1283. STDMETHOD(f7)();
  1284. STDMETHOD(f8)();
  1285. STDMETHOD(f9)();
  1286. STDMETHOD(f10)();
  1287. STDMETHOD(f11)();
  1288. STDMETHOD(f12)();
  1289. STDMETHOD(f13)();
  1290. STDMETHOD(f14)();
  1291. STDMETHOD(f15)();
  1292. STDMETHOD(f16)();
  1293. STDMETHOD(f17)();
  1294. STDMETHOD(f18)();
  1295. STDMETHOD(f19)();
  1296. STDMETHOD(f20)();
  1297. STDMETHOD(f21)();
  1298. STDMETHOD(f22)();
  1299. STDMETHOD(f23)();
  1300. STDMETHOD(f24)();
  1301. STDMETHOD(f25)();
  1302. STDMETHOD(f26)();
  1303. STDMETHOD(f27)();
  1304. STDMETHOD(f28)();
  1305. STDMETHOD(f29)();
  1306. STDMETHOD(f30)();
  1307. STDMETHOD(f31)();
  1308. STDMETHOD(f32)();
  1309. STDMETHOD(f33)();
  1310. STDMETHOD(f34)();
  1311. STDMETHOD(f35)();
  1312. STDMETHOD(f36)();
  1313. STDMETHOD(f37)();
  1314. STDMETHOD(f38)();
  1315. STDMETHOD(f39)();
  1316. STDMETHOD(f40)();
  1317. STDMETHOD(f41)();
  1318. STDMETHOD(f42)();
  1319. STDMETHOD(f43)();
  1320. STDMETHOD(f44)();
  1321. STDMETHOD(f45)();
  1322. STDMETHOD(f46)();
  1323. STDMETHOD(f47)();
  1324. STDMETHOD(f48)();
  1325. STDMETHOD(f49)();
  1326. STDMETHOD(f50)();
  1327. STDMETHOD(f51)();
  1328. STDMETHOD(f52)();
  1329. STDMETHOD(f53)();
  1330. STDMETHOD(f54)();
  1331. STDMETHOD(f55)();
  1332. STDMETHOD(f56)();
  1333. STDMETHOD(f57)();
  1334. STDMETHOD(f58)();
  1335. STDMETHOD(f59)();
  1336. STDMETHOD(f60)();
  1337. STDMETHOD(f61)();
  1338. STDMETHOD(f62)();
  1339. STDMETHOD(f63)();
  1340. STDMETHOD(f64)();
  1341. STDMETHOD(f65)();
  1342. STDMETHOD(f66)();
  1343. STDMETHOD(f67)();
  1344. STDMETHOD(f68)();
  1345. STDMETHOD(f69)();
  1346. STDMETHOD(f70)();
  1347. STDMETHOD(f71)();
  1348. STDMETHOD(f72)();
  1349. STDMETHOD(f73)();
  1350. STDMETHOD(f74)();
  1351. STDMETHOD(f75)();
  1352. STDMETHOD(f76)();
  1353. STDMETHOD(f77)();
  1354. STDMETHOD(f78)();
  1355. STDMETHOD(f79)();
  1356. STDMETHOD(f80)();
  1357. STDMETHOD(f81)();
  1358. STDMETHOD(f82)();
  1359. STDMETHOD(f83)();
  1360. STDMETHOD(f84)();
  1361. STDMETHOD(f85)();
  1362. STDMETHOD(f86)();
  1363. STDMETHOD(f87)();
  1364. STDMETHOD(f88)();
  1365. STDMETHOD(f89)();
  1366. STDMETHOD(f90)();
  1367. STDMETHOD(f91)();
  1368. STDMETHOD(f92)();
  1369. STDMETHOD(f93)();
  1370. STDMETHOD(f94)();
  1371. STDMETHOD(f95)();
  1372. STDMETHOD(f96)();
  1373. STDMETHOD(f97)();
  1374. STDMETHOD(f98)();
  1375. STDMETHOD(f99)();
  1376. STDMETHOD(f100)();
  1377. STDMETHOD(f101)();
  1378. STDMETHOD(f102)();
  1379. STDMETHOD(f103)();
  1380. STDMETHOD(f104)();
  1381. STDMETHOD(f105)();
  1382. STDMETHOD(f106)();
  1383. STDMETHOD(f107)();
  1384. STDMETHOD(f108)();
  1385. STDMETHOD(f109)();
  1386. STDMETHOD(f110)();
  1387. STDMETHOD(f111)();
  1388. STDMETHOD(f112)();
  1389. STDMETHOD(f113)();
  1390. STDMETHOD(f114)();
  1391. STDMETHOD(f115)();
  1392. STDMETHOD(f116)();
  1393. STDMETHOD(f117)();
  1394. STDMETHOD(f118)();
  1395. STDMETHOD(f119)();
  1396. STDMETHOD(f120)();
  1397. STDMETHOD(f121)();
  1398. STDMETHOD(f122)();
  1399. STDMETHOD(f123)();
  1400. STDMETHOD(f124)();
  1401. STDMETHOD(f125)();
  1402. STDMETHOD(f126)();
  1403. STDMETHOD(f127)();
  1404. STDMETHOD(f128)();
  1405. STDMETHOD(f129)();
  1406. STDMETHOD(f130)();
  1407. STDMETHOD(f131)();
  1408. STDMETHOD(f132)();
  1409. STDMETHOD(f133)();
  1410. STDMETHOD(f134)();
  1411. STDMETHOD(f135)();
  1412. STDMETHOD(f136)();
  1413. STDMETHOD(f137)();
  1414. STDMETHOD(f138)();
  1415. STDMETHOD(f139)();
  1416. STDMETHOD(f140)();
  1417. STDMETHOD(f141)();
  1418. STDMETHOD(f142)();
  1419. STDMETHOD(f143)();
  1420. STDMETHOD(f144)();
  1421. STDMETHOD(f145)();
  1422. STDMETHOD(f146)();
  1423. STDMETHOD(f147)();
  1424. STDMETHOD(f148)();
  1425. STDMETHOD(f149)();
  1426. STDMETHOD(f150)();
  1427. STDMETHOD(f151)();
  1428. STDMETHOD(f152)();
  1429. STDMETHOD(f153)();
  1430. STDMETHOD(f154)();
  1431. STDMETHOD(f155)();
  1432. STDMETHOD(f156)();
  1433. STDMETHOD(f157)();
  1434. STDMETHOD(f158)();
  1435. STDMETHOD(f159)();
  1436. STDMETHOD(f160)();
  1437. STDMETHOD(f161)();
  1438. STDMETHOD(f162)();
  1439. STDMETHOD(f163)();
  1440. STDMETHOD(f164)();
  1441. STDMETHOD(f165)();
  1442. STDMETHOD(f166)();
  1443. STDMETHOD(f167)();
  1444. STDMETHOD(f168)();
  1445. STDMETHOD(f169)();
  1446. STDMETHOD(f170)();
  1447. STDMETHOD(f171)();
  1448. STDMETHOD(f172)();
  1449. STDMETHOD(f173)();
  1450. STDMETHOD(f174)();
  1451. STDMETHOD(f175)();
  1452. STDMETHOD(f176)();
  1453. STDMETHOD(f177)();
  1454. STDMETHOD(f178)();
  1455. STDMETHOD(f179)();
  1456. STDMETHOD(f180)();
  1457. STDMETHOD(f181)();
  1458. STDMETHOD(f182)();
  1459. STDMETHOD(f183)();
  1460. STDMETHOD(f184)();
  1461. STDMETHOD(f185)();
  1462. STDMETHOD(f186)();
  1463. STDMETHOD(f187)();
  1464. STDMETHOD(f188)();
  1465. STDMETHOD(f189)();
  1466. STDMETHOD(f190)();
  1467. STDMETHOD(f191)();
  1468. STDMETHOD(f192)();
  1469. STDMETHOD(f193)();
  1470. STDMETHOD(f194)();
  1471. STDMETHOD(f195)();
  1472. STDMETHOD(f196)();
  1473. STDMETHOD(f197)();
  1474. STDMETHOD(f198)();
  1475. STDMETHOD(f199)();
  1476. STDMETHOD(f200)();
  1477. STDMETHOD(f201)();
  1478. STDMETHOD(f202)();
  1479. STDMETHOD(f203)();
  1480. STDMETHOD(f204)();
  1481. STDMETHOD(f205)();
  1482. STDMETHOD(f206)();
  1483. STDMETHOD(f207)();
  1484. STDMETHOD(f208)();
  1485. STDMETHOD(f209)();
  1486. STDMETHOD(f210)();
  1487. STDMETHOD(f211)();
  1488. STDMETHOD(f212)();
  1489. STDMETHOD(f213)();
  1490. STDMETHOD(f214)();
  1491. STDMETHOD(f215)();
  1492. STDMETHOD(f216)();
  1493. STDMETHOD(f217)();
  1494. STDMETHOD(f218)();
  1495. STDMETHOD(f219)();
  1496. STDMETHOD(f220)();
  1497. STDMETHOD(f221)();
  1498. STDMETHOD(f222)();
  1499. STDMETHOD(f223)();
  1500. STDMETHOD(f224)();
  1501. STDMETHOD(f225)();
  1502. STDMETHOD(f226)();
  1503. STDMETHOD(f227)();
  1504. STDMETHOD(f228)();
  1505. STDMETHOD(f229)();
  1506. STDMETHOD(f230)();
  1507. STDMETHOD(f231)();
  1508. STDMETHOD(f232)();
  1509. STDMETHOD(f233)();
  1510. STDMETHOD(f234)();
  1511. STDMETHOD(f235)();
  1512. STDMETHOD(f236)();
  1513. STDMETHOD(f237)();
  1514. STDMETHOD(f238)();
  1515. STDMETHOD(f239)();
  1516. STDMETHOD(f240)();
  1517. STDMETHOD(f241)();
  1518. STDMETHOD(f242)();
  1519. STDMETHOD(f243)();
  1520. STDMETHOD(f244)();
  1521. STDMETHOD(f245)();
  1522. STDMETHOD(f246)();
  1523. STDMETHOD(f247)();
  1524. STDMETHOD(f248)();
  1525. STDMETHOD(f249)();
  1526. STDMETHOD(f250)();
  1527. STDMETHOD(f251)();
  1528. STDMETHOD(f252)();
  1529. STDMETHOD(f253)();
  1530. STDMETHOD(f254)();
  1531. STDMETHOD(f255)();
  1532. STDMETHOD(f256)();
  1533. STDMETHOD(f257)();
  1534. STDMETHOD(f258)();
  1535. STDMETHOD(f259)();
  1536. STDMETHOD(f260)();
  1537. STDMETHOD(f261)();
  1538. STDMETHOD(f262)();
  1539. STDMETHOD(f263)();
  1540. STDMETHOD(f264)();
  1541. STDMETHOD(f265)();
  1542. STDMETHOD(f266)();
  1543. STDMETHOD(f267)();
  1544. STDMETHOD(f268)();
  1545. STDMETHOD(f269)();
  1546. STDMETHOD(f270)();
  1547. STDMETHOD(f271)();
  1548. STDMETHOD(f272)();
  1549. STDMETHOD(f273)();
  1550. STDMETHOD(f274)();
  1551. STDMETHOD(f275)();
  1552. STDMETHOD(f276)();
  1553. STDMETHOD(f277)();
  1554. STDMETHOD(f278)();
  1555. STDMETHOD(f279)();
  1556. STDMETHOD(f280)();
  1557. STDMETHOD(f281)();
  1558. STDMETHOD(f282)();
  1559. STDMETHOD(f283)();
  1560. STDMETHOD(f284)();
  1561. STDMETHOD(f285)();
  1562. STDMETHOD(f286)();
  1563. STDMETHOD(f287)();
  1564. STDMETHOD(f288)();
  1565. STDMETHOD(f289)();
  1566. STDMETHOD(f290)();
  1567. STDMETHOD(f291)();
  1568. STDMETHOD(f292)();
  1569. STDMETHOD(f293)();
  1570. STDMETHOD(f294)();
  1571. STDMETHOD(f295)();
  1572. STDMETHOD(f296)();
  1573. STDMETHOD(f297)();
  1574. STDMETHOD(f298)();
  1575. STDMETHOD(f299)();
  1576. STDMETHOD(f300)();
  1577. STDMETHOD(f301)();
  1578. STDMETHOD(f302)();
  1579. STDMETHOD(f303)();
  1580. STDMETHOD(f304)();
  1581. STDMETHOD(f305)();
  1582. STDMETHOD(f306)();
  1583. STDMETHOD(f307)();
  1584. STDMETHOD(f308)();
  1585. STDMETHOD(f309)();
  1586. STDMETHOD(f310)();
  1587. STDMETHOD(f311)();
  1588. STDMETHOD(f312)();
  1589. STDMETHOD(f313)();
  1590. STDMETHOD(f314)();
  1591. STDMETHOD(f315)();
  1592. STDMETHOD(f316)();
  1593. STDMETHOD(f317)();
  1594. STDMETHOD(f318)();
  1595. STDMETHOD(f319)();
  1596. STDMETHOD(f320)();
  1597. STDMETHOD(f321)();
  1598. STDMETHOD(f322)();
  1599. STDMETHOD(f323)();
  1600. STDMETHOD(f324)();
  1601. STDMETHOD(f325)();
  1602. STDMETHOD(f326)();
  1603. STDMETHOD(f327)();
  1604. STDMETHOD(f328)();
  1605. STDMETHOD(f329)();
  1606. STDMETHOD(f330)();
  1607. STDMETHOD(f331)();
  1608. STDMETHOD(f332)();
  1609. STDMETHOD(f333)();
  1610. STDMETHOD(f334)();
  1611. STDMETHOD(f335)();
  1612. STDMETHOD(f336)();
  1613. STDMETHOD(f337)();
  1614. STDMETHOD(f338)();
  1615. STDMETHOD(f339)();
  1616. STDMETHOD(f340)();
  1617. STDMETHOD(f341)();
  1618. STDMETHOD(f342)();
  1619. STDMETHOD(f343)();
  1620. STDMETHOD(f344)();
  1621. STDMETHOD(f345)();
  1622. STDMETHOD(f346)();
  1623. STDMETHOD(f347)();
  1624. STDMETHOD(f348)();
  1625. STDMETHOD(f349)();
  1626. STDMETHOD(f350)();
  1627. STDMETHOD(f351)();
  1628. STDMETHOD(f352)();
  1629. STDMETHOD(f353)();
  1630. STDMETHOD(f354)();
  1631. STDMETHOD(f355)();
  1632. STDMETHOD(f356)();
  1633. STDMETHOD(f357)();
  1634. STDMETHOD(f358)();
  1635. STDMETHOD(f359)();
  1636. STDMETHOD(f360)();
  1637. STDMETHOD(f361)();
  1638. STDMETHOD(f362)();
  1639. STDMETHOD(f363)();
  1640. STDMETHOD(f364)();
  1641. STDMETHOD(f365)();
  1642. STDMETHOD(f366)();
  1643. STDMETHOD(f367)();
  1644. STDMETHOD(f368)();
  1645. STDMETHOD(f369)();
  1646. STDMETHOD(f370)();
  1647. STDMETHOD(f371)();
  1648. STDMETHOD(f372)();
  1649. STDMETHOD(f373)();
  1650. STDMETHOD(f374)();
  1651. STDMETHOD(f375)();
  1652. STDMETHOD(f376)();
  1653. STDMETHOD(f377)();
  1654. STDMETHOD(f378)();
  1655. STDMETHOD(f379)();
  1656. STDMETHOD(f380)();
  1657. STDMETHOD(f381)();
  1658. STDMETHOD(f382)();
  1659. STDMETHOD(f383)();
  1660. STDMETHOD(f384)();
  1661. STDMETHOD(f385)();
  1662. STDMETHOD(f386)();
  1663. STDMETHOD(f387)();
  1664. STDMETHOD(f388)();
  1665. STDMETHOD(f389)();
  1666. STDMETHOD(f390)();
  1667. STDMETHOD(f391)();
  1668. STDMETHOD(f392)();
  1669. STDMETHOD(f393)();
  1670. STDMETHOD(f394)();
  1671. STDMETHOD(f395)();
  1672. STDMETHOD(f396)();
  1673. STDMETHOD(f397)();
  1674. STDMETHOD(f398)();
  1675. STDMETHOD(f399)();
  1676. STDMETHOD(f400)();
  1677. STDMETHOD(f401)();
  1678. STDMETHOD(f402)();
  1679. STDMETHOD(f403)();
  1680. STDMETHOD(f404)();
  1681. STDMETHOD(f405)();
  1682. STDMETHOD(f406)();
  1683. STDMETHOD(f407)();
  1684. STDMETHOD(f408)();
  1685. STDMETHOD(f409)();
  1686. STDMETHOD(f410)();
  1687. STDMETHOD(f411)();
  1688. STDMETHOD(f412)();
  1689. STDMETHOD(f413)();
  1690. STDMETHOD(f414)();
  1691. STDMETHOD(f415)();
  1692. STDMETHOD(f416)();
  1693. STDMETHOD(f417)();
  1694. STDMETHOD(f418)();
  1695. STDMETHOD(f419)();
  1696. STDMETHOD(f420)();
  1697. STDMETHOD(f421)();
  1698. STDMETHOD(f422)();
  1699. STDMETHOD(f423)();
  1700. STDMETHOD(f424)();
  1701. STDMETHOD(f425)();
  1702. STDMETHOD(f426)();
  1703. STDMETHOD(f427)();
  1704. STDMETHOD(f428)();
  1705. STDMETHOD(f429)();
  1706. STDMETHOD(f430)();
  1707. STDMETHOD(f431)();
  1708. STDMETHOD(f432)();
  1709. STDMETHOD(f433)();
  1710. STDMETHOD(f434)();
  1711. STDMETHOD(f435)();
  1712. STDMETHOD(f436)();
  1713. STDMETHOD(f437)();
  1714. STDMETHOD(f438)();
  1715. STDMETHOD(f439)();
  1716. STDMETHOD(f440)();
  1717. STDMETHOD(f441)();
  1718. STDMETHOD(f442)();
  1719. STDMETHOD(f443)();
  1720. STDMETHOD(f444)();
  1721. STDMETHOD(f445)();
  1722. STDMETHOD(f446)();
  1723. STDMETHOD(f447)();
  1724. STDMETHOD(f448)();
  1725. STDMETHOD(f449)();
  1726. STDMETHOD(f450)();
  1727. STDMETHOD(f451)();
  1728. STDMETHOD(f452)();
  1729. STDMETHOD(f453)();
  1730. STDMETHOD(f454)();
  1731. STDMETHOD(f455)();
  1732. STDMETHOD(f456)();
  1733. STDMETHOD(f457)();
  1734. STDMETHOD(f458)();
  1735. STDMETHOD(f459)();
  1736. STDMETHOD(f460)();
  1737. STDMETHOD(f461)();
  1738. STDMETHOD(f462)();
  1739. STDMETHOD(f463)();
  1740. STDMETHOD(f464)();
  1741. STDMETHOD(f465)();
  1742. STDMETHOD(f466)();
  1743. STDMETHOD(f467)();
  1744. STDMETHOD(f468)();
  1745. STDMETHOD(f469)();
  1746. STDMETHOD(f470)();
  1747. STDMETHOD(f471)();
  1748. STDMETHOD(f472)();
  1749. STDMETHOD(f473)();
  1750. STDMETHOD(f474)();
  1751. STDMETHOD(f475)();
  1752. STDMETHOD(f476)();
  1753. STDMETHOD(f477)();
  1754. STDMETHOD(f478)();
  1755. STDMETHOD(f479)();
  1756. STDMETHOD(f480)();
  1757. STDMETHOD(f481)();
  1758. STDMETHOD(f482)();
  1759. STDMETHOD(f483)();
  1760. STDMETHOD(f484)();
  1761. STDMETHOD(f485)();
  1762. STDMETHOD(f486)();
  1763. STDMETHOD(f487)();
  1764. STDMETHOD(f488)();
  1765. STDMETHOD(f489)();
  1766. STDMETHOD(f490)();
  1767. STDMETHOD(f491)();
  1768. STDMETHOD(f492)();
  1769. STDMETHOD(f493)();
  1770. STDMETHOD(f494)();
  1771. STDMETHOD(f495)();
  1772. STDMETHOD(f496)();
  1773. STDMETHOD(f497)();
  1774. STDMETHOD(f498)();
  1775. STDMETHOD(f499)();
  1776. STDMETHOD(f500)();
  1777. STDMETHOD(f501)();
  1778. STDMETHOD(f502)();
  1779. STDMETHOD(f503)();
  1780. STDMETHOD(f504)();
  1781. STDMETHOD(f505)();
  1782. STDMETHOD(f506)();
  1783. STDMETHOD(f507)();
  1784. STDMETHOD(f508)();
  1785. STDMETHOD(f509)();
  1786. STDMETHOD(f510)();
  1787. STDMETHOD(f511)();
  1788. STDMETHOD(f512)();
  1789. STDMETHOD(f513)();
  1790. STDMETHOD(f514)();
  1791. STDMETHOD(f515)();
  1792. STDMETHOD(f516)();
  1793. STDMETHOD(f517)();
  1794. STDMETHOD(f518)();
  1795. STDMETHOD(f519)();
  1796. STDMETHOD(f520)();
  1797. STDMETHOD(f521)();
  1798. STDMETHOD(f522)();
  1799. STDMETHOD(f523)();
  1800. STDMETHOD(f524)();
  1801. STDMETHOD(f525)();
  1802. STDMETHOD(f526)();
  1803. STDMETHOD(f527)();
  1804. STDMETHOD(f528)();
  1805. STDMETHOD(f529)();
  1806. STDMETHOD(f530)();
  1807. STDMETHOD(f531)();
  1808. STDMETHOD(f532)();
  1809. STDMETHOD(f533)();
  1810. STDMETHOD(f534)();
  1811. STDMETHOD(f535)();
  1812. STDMETHOD(f536)();
  1813. STDMETHOD(f537)();
  1814. STDMETHOD(f538)();
  1815. STDMETHOD(f539)();
  1816. STDMETHOD(f540)();
  1817. STDMETHOD(f541)();
  1818. STDMETHOD(f542)();
  1819. STDMETHOD(f543)();
  1820. STDMETHOD(f544)();
  1821. STDMETHOD(f545)();
  1822. STDMETHOD(f546)();
  1823. STDMETHOD(f547)();
  1824. STDMETHOD(f548)();
  1825. STDMETHOD(f549)();
  1826. STDMETHOD(f550)();
  1827. STDMETHOD(f551)();
  1828. STDMETHOD(f552)();
  1829. STDMETHOD(f553)();
  1830. STDMETHOD(f554)();
  1831. STDMETHOD(f555)();
  1832. STDMETHOD(f556)();
  1833. STDMETHOD(f557)();
  1834. STDMETHOD(f558)();
  1835. STDMETHOD(f559)();
  1836. STDMETHOD(f560)();
  1837. STDMETHOD(f561)();
  1838. STDMETHOD(f562)();
  1839. STDMETHOD(f563)();
  1840. STDMETHOD(f564)();
  1841. STDMETHOD(f565)();
  1842. STDMETHOD(f566)();
  1843. STDMETHOD(f567)();
  1844. STDMETHOD(f568)();
  1845. STDMETHOD(f569)();
  1846. STDMETHOD(f570)();
  1847. STDMETHOD(f571)();
  1848. STDMETHOD(f572)();
  1849. STDMETHOD(f573)();
  1850. STDMETHOD(f574)();
  1851. STDMETHOD(f575)();
  1852. STDMETHOD(f576)();
  1853. STDMETHOD(f577)();
  1854. STDMETHOD(f578)();
  1855. STDMETHOD(f579)();
  1856. STDMETHOD(f580)();
  1857. STDMETHOD(f581)();
  1858. STDMETHOD(f582)();
  1859. STDMETHOD(f583)();
  1860. STDMETHOD(f584)();
  1861. STDMETHOD(f585)();
  1862. STDMETHOD(f586)();
  1863. STDMETHOD(f587)();
  1864. STDMETHOD(f588)();
  1865. STDMETHOD(f589)();
  1866. STDMETHOD(f590)();
  1867. STDMETHOD(f591)();
  1868. STDMETHOD(f592)();
  1869. STDMETHOD(f593)();
  1870. STDMETHOD(f594)();
  1871. STDMETHOD(f595)();
  1872. STDMETHOD(f596)();
  1873. STDMETHOD(f597)();
  1874. STDMETHOD(f598)();
  1875. STDMETHOD(f599)();
  1876. STDMETHOD(f600)();
  1877. STDMETHOD(f601)();
  1878. STDMETHOD(f602)();
  1879. STDMETHOD(f603)();
  1880. STDMETHOD(f604)();
  1881. STDMETHOD(f605)();
  1882. STDMETHOD(f606)();
  1883. STDMETHOD(f607)();
  1884. STDMETHOD(f608)();
  1885. STDMETHOD(f609)();
  1886. STDMETHOD(f610)();
  1887. STDMETHOD(f611)();
  1888. STDMETHOD(f612)();
  1889. STDMETHOD(f613)();
  1890. STDMETHOD(f614)();
  1891. STDMETHOD(f615)();
  1892. STDMETHOD(f616)();
  1893. STDMETHOD(f617)();
  1894. STDMETHOD(f618)();
  1895. STDMETHOD(f619)();
  1896. STDMETHOD(f620)();
  1897. STDMETHOD(f621)();
  1898. STDMETHOD(f622)();
  1899. STDMETHOD(f623)();
  1900. STDMETHOD(f624)();
  1901. STDMETHOD(f625)();
  1902. STDMETHOD(f626)();
  1903. STDMETHOD(f627)();
  1904. STDMETHOD(f628)();
  1905. STDMETHOD(f629)();
  1906. STDMETHOD(f630)();
  1907. STDMETHOD(f631)();
  1908. STDMETHOD(f632)();
  1909. STDMETHOD(f633)();
  1910. STDMETHOD(f634)();
  1911. STDMETHOD(f635)();
  1912. STDMETHOD(f636)();
  1913. STDMETHOD(f637)();
  1914. STDMETHOD(f638)();
  1915. STDMETHOD(f639)();
  1916. STDMETHOD(f640)();
  1917. STDMETHOD(f641)();
  1918. STDMETHOD(f642)();
  1919. STDMETHOD(f643)();
  1920. STDMETHOD(f644)();
  1921. STDMETHOD(f645)();
  1922. STDMETHOD(f646)();
  1923. STDMETHOD(f647)();
  1924. STDMETHOD(f648)();
  1925. STDMETHOD(f649)();
  1926. STDMETHOD(f650)();
  1927. STDMETHOD(f651)();
  1928. STDMETHOD(f652)();
  1929. STDMETHOD(f653)();
  1930. STDMETHOD(f654)();
  1931. STDMETHOD(f655)();
  1932. STDMETHOD(f656)();
  1933. STDMETHOD(f657)();
  1934. STDMETHOD(f658)();
  1935. STDMETHOD(f659)();
  1936. STDMETHOD(f660)();
  1937. STDMETHOD(f661)();
  1938. STDMETHOD(f662)();
  1939. STDMETHOD(f663)();
  1940. STDMETHOD(f664)();
  1941. STDMETHOD(f665)();
  1942. STDMETHOD(f666)();
  1943. STDMETHOD(f667)();
  1944. STDMETHOD(f668)();
  1945. STDMETHOD(f669)();
  1946. STDMETHOD(f670)();
  1947. STDMETHOD(f671)();
  1948. STDMETHOD(f672)();
  1949. STDMETHOD(f673)();
  1950. STDMETHOD(f674)();
  1951. STDMETHOD(f675)();
  1952. STDMETHOD(f676)();
  1953. STDMETHOD(f677)();
  1954. STDMETHOD(f678)();
  1955. STDMETHOD(f679)();
  1956. STDMETHOD(f680)();
  1957. STDMETHOD(f681)();
  1958. STDMETHOD(f682)();
  1959. STDMETHOD(f683)();
  1960. STDMETHOD(f684)();
  1961. STDMETHOD(f685)();
  1962. STDMETHOD(f686)();
  1963. STDMETHOD(f687)();
  1964. STDMETHOD(f688)();
  1965. STDMETHOD(f689)();
  1966. STDMETHOD(f690)();
  1967. STDMETHOD(f691)();
  1968. STDMETHOD(f692)();
  1969. STDMETHOD(f693)();
  1970. STDMETHOD(f694)();
  1971. STDMETHOD(f695)();
  1972. STDMETHOD(f696)();
  1973. STDMETHOD(f697)();
  1974. STDMETHOD(f698)();
  1975. STDMETHOD(f699)();
  1976. STDMETHOD(f700)();
  1977. STDMETHOD(f701)();
  1978. STDMETHOD(f702)();
  1979. STDMETHOD(f703)();
  1980. STDMETHOD(f704)();
  1981. STDMETHOD(f705)();
  1982. STDMETHOD(f706)();
  1983. STDMETHOD(f707)();
  1984. STDMETHOD(f708)();
  1985. STDMETHOD(f709)();
  1986. STDMETHOD(f710)();
  1987. STDMETHOD(f711)();
  1988. STDMETHOD(f712)();
  1989. STDMETHOD(f713)();
  1990. STDMETHOD(f714)();
  1991. STDMETHOD(f715)();
  1992. STDMETHOD(f716)();
  1993. STDMETHOD(f717)();
  1994. STDMETHOD(f718)();
  1995. STDMETHOD(f719)();
  1996. STDMETHOD(f720)();
  1997. STDMETHOD(f721)();
  1998. STDMETHOD(f722)();
  1999. STDMETHOD(f723)();
  2000. STDMETHOD(f724)();
  2001. STDMETHOD(f725)();
  2002. STDMETHOD(f726)();
  2003. STDMETHOD(f727)();
  2004. STDMETHOD(f728)();
  2005. STDMETHOD(f729)();
  2006. STDMETHOD(f730)();
  2007. STDMETHOD(f731)();
  2008. STDMETHOD(f732)();
  2009. STDMETHOD(f733)();
  2010. STDMETHOD(f734)();
  2011. STDMETHOD(f735)();
  2012. STDMETHOD(f736)();
  2013. STDMETHOD(f737)();
  2014. STDMETHOD(f738)();
  2015. STDMETHOD(f739)();
  2016. STDMETHOD(f740)();
  2017. STDMETHOD(f741)();
  2018. STDMETHOD(f742)();
  2019. STDMETHOD(f743)();
  2020. STDMETHOD(f744)();
  2021. STDMETHOD(f745)();
  2022. STDMETHOD(f746)();
  2023. STDMETHOD(f747)();
  2024. STDMETHOD(f748)();
  2025. STDMETHOD(f749)();
  2026. STDMETHOD(f750)();
  2027. STDMETHOD(f751)();
  2028. STDMETHOD(f752)();
  2029. STDMETHOD(f753)();
  2030. STDMETHOD(f754)();
  2031. STDMETHOD(f755)();
  2032. STDMETHOD(f756)();
  2033. STDMETHOD(f757)();
  2034. STDMETHOD(f758)();
  2035. STDMETHOD(f759)();
  2036. STDMETHOD(f760)();
  2037. STDMETHOD(f761)();
  2038. STDMETHOD(f762)();
  2039. STDMETHOD(f763)();
  2040. STDMETHOD(f764)();
  2041. STDMETHOD(f765)();
  2042. STDMETHOD(f766)();
  2043. STDMETHOD(f767)();
  2044. STDMETHOD(f768)();
  2045. STDMETHOD(f769)();
  2046. STDMETHOD(f770)();
  2047. STDMETHOD(f771)();
  2048. STDMETHOD(f772)();
  2049. STDMETHOD(f773)();
  2050. STDMETHOD(f774)();
  2051. STDMETHOD(f775)();
  2052. STDMETHOD(f776)();
  2053. STDMETHOD(f777)();
  2054. STDMETHOD(f778)();
  2055. STDMETHOD(f779)();
  2056. STDMETHOD(f780)();
  2057. STDMETHOD(f781)();
  2058. STDMETHOD(f782)();
  2059. STDMETHOD(f783)();
  2060. STDMETHOD(f784)();
  2061. STDMETHOD(f785)();
  2062. STDMETHOD(f786)();
  2063. STDMETHOD(f787)();
  2064. STDMETHOD(f788)();
  2065. STDMETHOD(f789)();
  2066. STDMETHOD(f790)();
  2067. STDMETHOD(f791)();
  2068. STDMETHOD(f792)();
  2069. STDMETHOD(f793)();
  2070. STDMETHOD(f794)();
  2071. STDMETHOD(f795)();
  2072. STDMETHOD(f796)();
  2073. STDMETHOD(f797)();
  2074. STDMETHOD(f798)();
  2075. STDMETHOD(f799)();
  2076. STDMETHOD(f800)();
  2077. STDMETHOD(f801)();
  2078. STDMETHOD(f802)();
  2079. STDMETHOD(f803)();
  2080. STDMETHOD(f804)();
  2081. STDMETHOD(f805)();
  2082. STDMETHOD(f806)();
  2083. STDMETHOD(f807)();
  2084. STDMETHOD(f808)();
  2085. STDMETHOD(f809)();
  2086. STDMETHOD(f810)();
  2087. STDMETHOD(f811)();
  2088. STDMETHOD(f812)();
  2089. STDMETHOD(f813)();
  2090. STDMETHOD(f814)();
  2091. STDMETHOD(f815)();
  2092. STDMETHOD(f816)();
  2093. STDMETHOD(f817)();
  2094. STDMETHOD(f818)();
  2095. STDMETHOD(f819)();
  2096. STDMETHOD(f820)();
  2097. STDMETHOD(f821)();
  2098. STDMETHOD(f822)();
  2099. STDMETHOD(f823)();
  2100. STDMETHOD(f824)();
  2101. STDMETHOD(f825)();
  2102. STDMETHOD(f826)();
  2103. STDMETHOD(f827)();
  2104. STDMETHOD(f828)();
  2105. STDMETHOD(f829)();
  2106. STDMETHOD(f830)();
  2107. STDMETHOD(f831)();
  2108. STDMETHOD(f832)();
  2109. STDMETHOD(f833)();
  2110. STDMETHOD(f834)();
  2111. STDMETHOD(f835)();
  2112. STDMETHOD(f836)();
  2113. STDMETHOD(f837)();
  2114. STDMETHOD(f838)();
  2115. STDMETHOD(f839)();
  2116. STDMETHOD(f840)();
  2117. STDMETHOD(f841)();
  2118. STDMETHOD(f842)();
  2119. STDMETHOD(f843)();
  2120. STDMETHOD(f844)();
  2121. STDMETHOD(f845)();
  2122. STDMETHOD(f846)();
  2123. STDMETHOD(f847)();
  2124. STDMETHOD(f848)();
  2125. STDMETHOD(f849)();
  2126. STDMETHOD(f850)();
  2127. STDMETHOD(f851)();
  2128. STDMETHOD(f852)();
  2129. STDMETHOD(f853)();
  2130. STDMETHOD(f854)();
  2131. STDMETHOD(f855)();
  2132. STDMETHOD(f856)();
  2133. STDMETHOD(f857)();
  2134. STDMETHOD(f858)();
  2135. STDMETHOD(f859)();
  2136. STDMETHOD(f860)();
  2137. STDMETHOD(f861)();
  2138. STDMETHOD(f862)();
  2139. STDMETHOD(f863)();
  2140. STDMETHOD(f864)();
  2141. STDMETHOD(f865)();
  2142. STDMETHOD(f866)();
  2143. STDMETHOD(f867)();
  2144. STDMETHOD(f868)();
  2145. STDMETHOD(f869)();
  2146. STDMETHOD(f870)();
  2147. STDMETHOD(f871)();
  2148. STDMETHOD(f872)();
  2149. STDMETHOD(f873)();
  2150. STDMETHOD(f874)();
  2151. STDMETHOD(f875)();
  2152. STDMETHOD(f876)();
  2153. STDMETHOD(f877)();
  2154. STDMETHOD(f878)();
  2155. STDMETHOD(f879)();
  2156. STDMETHOD(f880)();
  2157. STDMETHOD(f881)();
  2158. STDMETHOD(f882)();
  2159. STDMETHOD(f883)();
  2160. STDMETHOD(f884)();
  2161. STDMETHOD(f885)();
  2162. STDMETHOD(f886)();
  2163. STDMETHOD(f887)();
  2164. STDMETHOD(f888)();
  2165. STDMETHOD(f889)();
  2166. STDMETHOD(f890)();
  2167. STDMETHOD(f891)();
  2168. STDMETHOD(f892)();
  2169. STDMETHOD(f893)();
  2170. STDMETHOD(f894)();
  2171. STDMETHOD(f895)();
  2172. STDMETHOD(f896)();
  2173. STDMETHOD(f897)();
  2174. STDMETHOD(f898)();
  2175. STDMETHOD(f899)();
  2176. STDMETHOD(f900)();
  2177. STDMETHOD(f901)();
  2178. STDMETHOD(f902)();
  2179. STDMETHOD(f903)();
  2180. STDMETHOD(f904)();
  2181. STDMETHOD(f905)();
  2182. STDMETHOD(f906)();
  2183. STDMETHOD(f907)();
  2184. STDMETHOD(f908)();
  2185. STDMETHOD(f909)();
  2186. STDMETHOD(f910)();
  2187. STDMETHOD(f911)();
  2188. STDMETHOD(f912)();
  2189. STDMETHOD(f913)();
  2190. STDMETHOD(f914)();
  2191. STDMETHOD(f915)();
  2192. STDMETHOD(f916)();
  2193. STDMETHOD(f917)();
  2194. STDMETHOD(f918)();
  2195. STDMETHOD(f919)();
  2196. STDMETHOD(f920)();
  2197. STDMETHOD(f921)();
  2198. STDMETHOD(f922)();
  2199. STDMETHOD(f923)();
  2200. STDMETHOD(f924)();
  2201. STDMETHOD(f925)();
  2202. STDMETHOD(f926)();
  2203. STDMETHOD(f927)();
  2204. STDMETHOD(f928)();
  2205. STDMETHOD(f929)();
  2206. STDMETHOD(f930)();
  2207. STDMETHOD(f931)();
  2208. STDMETHOD(f932)();
  2209. STDMETHOD(f933)();
  2210. STDMETHOD(f934)();
  2211. STDMETHOD(f935)();
  2212. STDMETHOD(f936)();
  2213. STDMETHOD(f937)();
  2214. STDMETHOD(f938)();
  2215. STDMETHOD(f939)();
  2216. STDMETHOD(f940)();
  2217. STDMETHOD(f941)();
  2218. STDMETHOD(f942)();
  2219. STDMETHOD(f943)();
  2220. STDMETHOD(f944)();
  2221. STDMETHOD(f945)();
  2222. STDMETHOD(f946)();
  2223. STDMETHOD(f947)();
  2224. STDMETHOD(f948)();
  2225. STDMETHOD(f949)();
  2226. STDMETHOD(f950)();
  2227. STDMETHOD(f951)();
  2228. STDMETHOD(f952)();
  2229. STDMETHOD(f953)();
  2230. STDMETHOD(f954)();
  2231. STDMETHOD(f955)();
  2232. STDMETHOD(f956)();
  2233. STDMETHOD(f957)();
  2234. STDMETHOD(f958)();
  2235. STDMETHOD(f959)();
  2236. STDMETHOD(f960)();
  2237. STDMETHOD(f961)();
  2238. STDMETHOD(f962)();
  2239. STDMETHOD(f963)();
  2240. STDMETHOD(f964)();
  2241. STDMETHOD(f965)();
  2242. STDMETHOD(f966)();
  2243. STDMETHOD(f967)();
  2244. STDMETHOD(f968)();
  2245. STDMETHOD(f969)();
  2246. STDMETHOD(f970)();
  2247. STDMETHOD(f971)();
  2248. STDMETHOD(f972)();
  2249. STDMETHOD(f973)();
  2250. STDMETHOD(f974)();
  2251. STDMETHOD(f975)();
  2252. STDMETHOD(f976)();
  2253. STDMETHOD(f977)();
  2254. STDMETHOD(f978)();
  2255. STDMETHOD(f979)();
  2256. STDMETHOD(f980)();
  2257. STDMETHOD(f981)();
  2258. STDMETHOD(f982)();
  2259. STDMETHOD(f983)();
  2260. STDMETHOD(f984)();
  2261. STDMETHOD(f985)();
  2262. STDMETHOD(f986)();
  2263. STDMETHOD(f987)();
  2264. STDMETHOD(f988)();
  2265. STDMETHOD(f989)();
  2266. STDMETHOD(f990)();
  2267. STDMETHOD(f991)();
  2268. STDMETHOD(f992)();
  2269. STDMETHOD(f993)();
  2270. STDMETHOD(f994)();
  2271. STDMETHOD(f995)();
  2272. STDMETHOD(f996)();
  2273. STDMETHOD(f997)();
  2274. STDMETHOD(f998)();
  2275. STDMETHOD(f999)();
  2276. STDMETHOD(f1000)();
  2277. STDMETHOD(f1001)();
  2278. STDMETHOD(f1002)();
  2279. STDMETHOD(f1003)();
  2280. STDMETHOD(f1004)();
  2281. STDMETHOD(f1005)();
  2282. STDMETHOD(f1006)();
  2283. STDMETHOD(f1007)();
  2284. STDMETHOD(f1008)();
  2285. STDMETHOD(f1009)();
  2286. STDMETHOD(f1010)();
  2287. STDMETHOD(f1011)();
  2288. STDMETHOD(f1012)();
  2289. STDMETHOD(f1013)();
  2290. STDMETHOD(f1014)();
  2291. STDMETHOD(f1015)();
  2292. STDMETHOD(f1016)();
  2293. STDMETHOD(f1017)();
  2294. STDMETHOD(f1018)();
  2295. STDMETHOD(f1019)();
  2296. STDMETHOD(f1020)();
  2297. STDMETHOD(f1021)();
  2298. STDMETHOD(f1022)();
  2299. STDMETHOD(f1023)();
  2300. STDMETHOD(f1024)();
  2301. _QIThunk(IUnknown* pOrig, LPCTSTR p, const IID& i, UINT n, bool b)
  2302. {
  2303. lpszClassName = p;
  2304. iid = i;
  2305. nIndex = n;
  2306. m_dwRef = 0;
  2307. m_dwMaxRef = 0;
  2308. pUnk = pOrig;
  2309. bBreak = b;
  2310. bNonAddRefThunk = false;
  2311. }
  2312. IUnknown* pUnk;
  2313. long m_dwRef;
  2314. long m_dwMaxRef;
  2315. LPCTSTR lpszClassName;
  2316. IID iid;
  2317. UINT nIndex;
  2318. bool bBreak;
  2319. bool bNonAddRefThunk;
  2320. void Dump()
  2321. {
  2322. TCHAR buf[256];
  2323. if (m_dwRef != 0)
  2324. {
  2325. wsprintf(buf, _T("INTERFACE LEAK: RefCount = %d, MaxRefCount = %d, {Allocation = %d} "), m_dwRef, m_dwMaxRef, nIndex);
  2326. OutputDebugString(buf);
  2327. AtlDumpIID(iid, lpszClassName, S_OK);
  2328. }
  2329. else
  2330. {
  2331. wsprintf(buf, _T("NonAddRef Thunk LEAK: {Allocation = %d}\n"), nIndex);
  2332. OutputDebugString(buf);
  2333. }
  2334. }
  2335. };
  2336. #endif
  2337. /////////////////////////////////////////////////////////////////////////////
  2338. // Collection helpers - CSimpleArray & CSimpleMap
  2339. template <class T>
  2340. class CSimpleArray
  2341. {
  2342. public:
  2343. T* m_aT;
  2344. int m_nSize;
  2345. int m_nAllocSize;
  2346. // Construction/destruction
  2347. CSimpleArray() : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
  2348. { }
  2349. ~CSimpleArray()
  2350. {
  2351. RemoveAll();
  2352. }
  2353. // Operations
  2354. int GetSize() const
  2355. {
  2356. return m_nSize;
  2357. }
  2358. BOOL Add(T& t)
  2359. {
  2360. if(m_nSize == m_nAllocSize)
  2361. {
  2362. T* aT;
  2363. int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
  2364. aT = (T*)realloc(m_aT, nNewAllocSize * sizeof(T));
  2365. if(aT == NULL)
  2366. return FALSE;
  2367. m_nAllocSize = nNewAllocSize;
  2368. m_aT = aT;
  2369. }
  2370. m_nSize++;
  2371. SetAtIndex(m_nSize - 1, t);
  2372. return TRUE;
  2373. }
  2374. BOOL Remove(T& t)
  2375. {
  2376. int nIndex = Find(t);
  2377. if(nIndex == -1)
  2378. return FALSE;
  2379. return RemoveAt(nIndex);
  2380. }
  2381. BOOL RemoveAt(int nIndex)
  2382. {
  2383. if(nIndex != (m_nSize - 1))
  2384. {
  2385. #if _MSC_VER >= 1200
  2386. m_aT[nIndex].~T();
  2387. #else
  2388. T* MyT;
  2389. MyT = &m_aT[nIndex];
  2390. MyT->~T();
  2391. #endif
  2392. memmove((void*)&m_aT[nIndex], (void*)&m_aT[nIndex + 1], (m_nSize - (nIndex + 1)) * sizeof(T));
  2393. }
  2394. m_nSize--;
  2395. return TRUE;
  2396. }
  2397. void RemoveAll()
  2398. {
  2399. if(m_aT != NULL)
  2400. {
  2401. for(int i = 0; i < m_nSize; i++) {
  2402. #if _MSC_VER >= 1200
  2403. m_aT[i].~T();
  2404. #else
  2405. T* MyT;
  2406. MyT = &m_aT[i];
  2407. MyT->~T();
  2408. #endif
  2409. }
  2410. free(m_aT);
  2411. m_aT = NULL;
  2412. }
  2413. m_nSize = 0;
  2414. m_nAllocSize = 0;
  2415. }
  2416. T& operator[] (int nIndex) const
  2417. {
  2418. ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
  2419. return m_aT[nIndex];
  2420. }
  2421. T* GetData() const
  2422. {
  2423. return m_aT;
  2424. }
  2425. // Implementation
  2426. class Wrapper
  2427. {
  2428. public:
  2429. Wrapper(T& _t) : t(_t)
  2430. {
  2431. }
  2432. template <class _Ty>
  2433. void *operator new(size_t, _Ty* p)
  2434. {
  2435. return p;
  2436. }
  2437. T t;
  2438. };
  2439. void SetAtIndex(int nIndex, T& t)
  2440. {
  2441. ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
  2442. new(m_aT + nIndex) Wrapper(t);
  2443. }
  2444. int Find(T& t) const
  2445. {
  2446. for(int i = 0; i < m_nSize; i++)
  2447. {
  2448. if(m_aT[i] == t)
  2449. return i;
  2450. }
  2451. return -1; // not found
  2452. }
  2453. };
  2454. // for arrays of simple types
  2455. template <class T>
  2456. class CSimpleValArray : public CSimpleArray< T >
  2457. {
  2458. public:
  2459. BOOL Add(T t)
  2460. {
  2461. return CSimpleArray< T >::Add(t);
  2462. }
  2463. BOOL Remove(T t)
  2464. {
  2465. return CSimpleArray< T >::Remove(t);
  2466. }
  2467. T operator[] (int nIndex) const
  2468. {
  2469. return CSimpleArray< T >::operator[](nIndex);
  2470. }
  2471. };
  2472. // intended for small number of simple types or pointers
  2473. template <class TKey, class TVal>
  2474. class CSimpleMap
  2475. {
  2476. public:
  2477. TKey* m_aKey;
  2478. TVal* m_aVal;
  2479. int m_nSize;
  2480. // Construction/destruction
  2481. CSimpleMap() : m_aKey(NULL), m_aVal(NULL), m_nSize(0)
  2482. { }
  2483. ~CSimpleMap()
  2484. {
  2485. RemoveAll();
  2486. }
  2487. // Operations
  2488. int GetSize() const
  2489. {
  2490. return m_nSize;
  2491. }
  2492. BOOL Add(TKey key, TVal val)
  2493. {
  2494. TKey* pKey;
  2495. pKey = (TKey*)realloc(m_aKey, (m_nSize + 1) * sizeof(TKey));
  2496. if(pKey == NULL)
  2497. return FALSE;
  2498. m_aKey = pKey;
  2499. TVal* pVal;
  2500. pVal = (TVal*)realloc(m_aVal, (m_nSize + 1) * sizeof(TVal));
  2501. if(pVal == NULL)
  2502. return FALSE;
  2503. m_aVal = pVal;
  2504. m_nSize++;
  2505. SetAtIndex(m_nSize - 1, key, val);
  2506. return TRUE;
  2507. }
  2508. BOOL Remove(TKey key)
  2509. {
  2510. int nIndex = FindKey(key);
  2511. if(nIndex == -1)
  2512. return FALSE;
  2513. if(nIndex != (m_nSize - 1))
  2514. {
  2515. m_aKey[nIndex].~TKey();
  2516. m_aVal[nIndex].~TVal();
  2517. memmove((void*)&m_aKey[nIndex], (void*)&m_aKey[nIndex + 1], (m_nSize - (nIndex + 1)) * sizeof(TKey));
  2518. memmove((void*)&m_aVal[nIndex], (void*)&m_aVal[nIndex + 1], (m_nSize - (nIndex + 1)) * sizeof(TVal));
  2519. }
  2520. TKey* pKey;
  2521. pKey = (TKey*)realloc(m_aKey, (m_nSize - 1) * sizeof(TKey));
  2522. if(pKey != NULL || m_nSize == 1)
  2523. m_aKey = pKey;
  2524. TVal* pVal;
  2525. pVal = (TVal*)realloc(m_aVal, (m_nSize - 1) * sizeof(TVal));
  2526. if(pVal != NULL || m_nSize == 1)
  2527. m_aVal = pVal;
  2528. m_nSize--;
  2529. return TRUE;
  2530. }
  2531. void RemoveAll()
  2532. {
  2533. if(m_aKey != NULL)
  2534. {
  2535. for(int i = 0; i < m_nSize; i++)
  2536. {
  2537. m_aKey[i].~TKey();
  2538. m_aVal[i].~TVal();
  2539. }
  2540. free(m_aKey);
  2541. m_aKey = NULL;
  2542. }
  2543. if(m_aVal != NULL)
  2544. {
  2545. free(m_aVal);
  2546. m_aVal = NULL;
  2547. }
  2548. m_nSize = 0;
  2549. }
  2550. BOOL SetAt(TKey key, TVal val)
  2551. {
  2552. int nIndex = FindKey(key);
  2553. if(nIndex == -1)
  2554. return FALSE;
  2555. SetAtIndex(nIndex, key, val);
  2556. return TRUE;
  2557. }
  2558. TVal Lookup(TKey key) const
  2559. {
  2560. int nIndex = FindKey(key);
  2561. if(nIndex == -1)
  2562. return NULL; // must be able to convert
  2563. return GetValueAt(nIndex);
  2564. }
  2565. TKey ReverseLookup(TVal val) const
  2566. {
  2567. int nIndex = FindVal(val);
  2568. if(nIndex == -1)
  2569. return NULL; // must be able to convert
  2570. return GetKeyAt(nIndex);
  2571. }
  2572. TKey& GetKeyAt(int nIndex) const
  2573. {
  2574. ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
  2575. return m_aKey[nIndex];
  2576. }
  2577. TVal& GetValueAt(int nIndex) const
  2578. {
  2579. ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
  2580. return m_aVal[nIndex];
  2581. }
  2582. // Implementation
  2583. template <typename T>
  2584. class Wrapper
  2585. {
  2586. public:
  2587. Wrapper(T& _t) : t(_t)
  2588. {
  2589. }
  2590. template <typename _Ty>
  2591. void *operator new(size_t, _Ty* p)
  2592. {
  2593. return p;
  2594. }
  2595. T t;
  2596. };
  2597. void SetAtIndex(int nIndex, TKey& key, TVal& val)
  2598. {
  2599. ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
  2600. new(m_aKey + nIndex) Wrapper<TKey>(key);
  2601. new(m_aVal + nIndex) Wrapper<TVal>(val);
  2602. }
  2603. int FindKey(TKey& key) const
  2604. {
  2605. for(int i = 0; i < m_nSize; i++)
  2606. {
  2607. if(m_aKey[i] == key)
  2608. return i;
  2609. }
  2610. return -1; // not found
  2611. }
  2612. int FindVal(TVal& val) const
  2613. {
  2614. for(int i = 0; i < m_nSize; i++)
  2615. {
  2616. if(m_aVal[i] == val)
  2617. return i;
  2618. }
  2619. return -1; // not found
  2620. }
  2621. };
  2622. class CComModule;
  2623. __declspec(selectany) CComModule* _pModule=NULL;
  2624. // {B62F5910-6528-11d1-9611-0000F81E0D0D}
  2625. _declspec(selectany) GUID GUID_ATLVer30 = { 0xb62f5910, 0x6528, 0x11d1, { 0x96, 0x11, 0x0, 0x0, 0xf8, 0x1e, 0xd, 0xd } };
  2626. class CComModule : public _ATL_MODULE
  2627. {
  2628. // Operations
  2629. public:
  2630. static GUID m_libid;
  2631. #ifdef _ATL_DEBUG_INTERFACES
  2632. UINT m_nIndexQI;
  2633. UINT m_nIndexBreakAt;
  2634. CSimpleArray<_QIThunk*>* m_paThunks;
  2635. #endif // _ATL_DEBUG_INTERFACES
  2636. void AddCreateWndData(_AtlCreateWndData* pData, void* pObject)
  2637. {
  2638. AtlModuleAddCreateWndData(this, pData, pObject);
  2639. }
  2640. void* ExtractCreateWndData()
  2641. {
  2642. return AtlModuleExtractCreateWndData(this);
  2643. }
  2644. LONG GetNextWindowID()
  2645. {
  2646. LONG nID;
  2647. nID = InterlockedIncrement(&m_nNextWindowID);
  2648. return nID;
  2649. }
  2650. HRESULT Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, const GUID* plibid = NULL)
  2651. {
  2652. pguidVer = &GUID_ATLVer30;
  2653. _pModule = this;
  2654. cbSize = sizeof(_ATL_MODULE);
  2655. dwAtlBuildVer = _ATL_VER;
  2656. AtlModuleInit(this, p, h);
  2657. if (plibid != NULL)
  2658. memcpy((void*)&m_libid, plibid, sizeof(GUID));
  2659. m_nNextWindowID = 1;
  2660. #ifdef _ATL_MIN_CRT
  2661. // Create a base heap
  2662. m_hHeap = HeapCreate(0, 0, 0);
  2663. #ifndef _ATL_NO_MP_HEAP
  2664. SYSTEM_INFO si;
  2665. GetSystemInfo(&si);
  2666. if (si.dwNumberOfProcessors > 1)
  2667. {
  2668. DWORD dwHeaps = si.dwNumberOfProcessors * 2;
  2669. m_dwHeaps = 0xFFFFFFFF;
  2670. for (int bits = 0; bits < 32; bits++)
  2671. {
  2672. if (dwHeaps & 0x80000000)
  2673. break;
  2674. dwHeaps <<= 1;
  2675. m_dwHeaps >>= 1;
  2676. }
  2677. m_dwHeaps >>= 1;
  2678. // Allocate more heaps for each processor
  2679. m_phHeaps = (HANDLE*) HeapAlloc(m_hHeap, _ATL_HEAPFLAGS, sizeof(HANDLE) * (m_dwHeaps + 1));
  2680. for (DWORD i = 0; i <= m_dwHeaps; i++)
  2681. m_phHeaps[i] = HeapCreate(0, 0, 0);
  2682. }
  2683. else
  2684. #endif
  2685. {
  2686. m_phHeaps = NULL;
  2687. m_dwHeaps = 0;
  2688. }
  2689. #endif
  2690. #ifdef _ATL_DEBUG_INTERFACES
  2691. m_nIndexQI = 0;
  2692. m_nIndexBreakAt = 0;
  2693. m_paThunks = NULL;
  2694. ATLTRY(m_paThunks = new CSimpleArray<_QIThunk*>);
  2695. if (m_paThunks == NULL)
  2696. return E_OUTOFMEMORY;
  2697. #endif // _ATL_DEBUG_INTERFACES
  2698. return S_OK;
  2699. }
  2700. #ifdef _ATL_DEBUG_INTERFACES
  2701. HRESULT AddThunk(IUnknown** pp, LPCTSTR lpsz, REFIID iid)
  2702. {
  2703. if ((pp == NULL) || (*pp == NULL))
  2704. return E_POINTER;
  2705. IUnknown* p = *pp;
  2706. _QIThunk* pThunk = NULL;
  2707. EnterCriticalSection(&m_csObjMap);
  2708. // Check if exists already for identity
  2709. if (InlineIsEqualUnknown(iid))
  2710. {
  2711. for (int i = 0; i < m_paThunks->GetSize(); i++)
  2712. {
  2713. if (m_paThunks->operator[](i)->pUnk == p)
  2714. {
  2715. m_paThunks->operator[](i)->InternalAddRef();
  2716. pThunk = m_paThunks->operator[](i);
  2717. break;
  2718. }
  2719. }
  2720. }
  2721. if (pThunk == NULL)
  2722. {
  2723. ++m_nIndexQI;
  2724. if (m_nIndexBreakAt == m_nIndexQI)
  2725. DebugBreak();
  2726. ATLTRY(pThunk = new _QIThunk(p, lpsz, iid, m_nIndexQI, (m_nIndexBreakAt == m_nIndexQI)));
  2727. if (pThunk == NULL)
  2728. return E_OUTOFMEMORY;
  2729. pThunk->InternalAddRef();
  2730. m_paThunks->Add(pThunk);
  2731. }
  2732. LeaveCriticalSection(&m_csObjMap);
  2733. *pp = (IUnknown*)pThunk;
  2734. return S_OK;
  2735. }
  2736. HRESULT AddNonAddRefThunk(IUnknown* p, LPCTSTR lpsz, IUnknown** ppThunkRet)
  2737. {
  2738. _QIThunk* pThunk = NULL;
  2739. EnterCriticalSection(&m_csObjMap);
  2740. // Check if exists already for identity
  2741. for (int i = 0; i < m_paThunks->GetSize(); i++)
  2742. {
  2743. if (m_paThunks->operator[](i)->pUnk == p)
  2744. {
  2745. m_paThunks->operator[](i)->bNonAddRefThunk = true;
  2746. pThunk = m_paThunks->operator[](i);
  2747. break;
  2748. }
  2749. }
  2750. if (pThunk == NULL)
  2751. {
  2752. ++m_nIndexQI;
  2753. if (m_nIndexBreakAt == m_nIndexQI)
  2754. DebugBreak();
  2755. ATLTRY(pThunk = new _QIThunk(p, lpsz, IID_IUnknown, m_nIndexQI, (m_nIndexBreakAt == m_nIndexQI)));
  2756. if (pThunk == NULL)
  2757. {
  2758. *ppThunkRet = NULL;
  2759. return E_OUTOFMEMORY;
  2760. }
  2761. pThunk->bNonAddRefThunk = true;
  2762. m_paThunks->Add(pThunk);
  2763. }
  2764. LeaveCriticalSection(&m_csObjMap);
  2765. *ppThunkRet = (IUnknown*)pThunk;
  2766. return S_OK;;
  2767. }
  2768. void DeleteNonAddRefThunk(IUnknown* pUnk)
  2769. {
  2770. EnterCriticalSection(&m_csObjMap);
  2771. for (int i = 0; i < m_paThunks->GetSize(); i++)
  2772. {
  2773. if (m_paThunks->operator[](i)->pUnk == pUnk)
  2774. {
  2775. delete m_paThunks->operator[](i);
  2776. m_paThunks->RemoveAt(i);
  2777. break;
  2778. }
  2779. }
  2780. LeaveCriticalSection(&m_csObjMap);
  2781. }
  2782. void DeleteThunk(_QIThunk* p)
  2783. {
  2784. EnterCriticalSection(&m_csObjMap);
  2785. int nIndex = m_paThunks->Find(p);
  2786. if (nIndex != -1)
  2787. {
  2788. delete m_paThunks->operator[](nIndex);
  2789. m_paThunks->RemoveAt(nIndex);
  2790. }
  2791. LeaveCriticalSection(&m_csObjMap);
  2792. }
  2793. bool DumpLeakedThunks()
  2794. {
  2795. bool b = false;
  2796. for (int i = 0; i < m_paThunks->GetSize(); i++)
  2797. {
  2798. b = true;
  2799. m_paThunks->operator[](i)->Dump();
  2800. delete m_paThunks->operator[](i);
  2801. }
  2802. m_paThunks->RemoveAll();
  2803. return b;
  2804. }
  2805. #endif // _ATL_DEBUG_INTERFACES
  2806. void Term()
  2807. {
  2808. #ifdef _ATL_DEBUG_INTERFACES
  2809. m_bDestroyHeap = false; // prevent heap from going away
  2810. AtlModuleTerm(this);
  2811. DumpLeakedThunks();
  2812. delete m_paThunks;
  2813. #ifndef _ATL_NO_MP_HEAP
  2814. if (m_phHeaps != NULL)
  2815. {
  2816. for (DWORD i = 0; i <= m_dwHeaps; i++)
  2817. HeapDestroy(m_phHeaps[i]);
  2818. }
  2819. #endif
  2820. if (m_hHeap != NULL)
  2821. HeapDestroy(m_hHeap);
  2822. #else
  2823. AtlModuleTerm(this);
  2824. #endif // _ATL_DEBUG_INTERFACES
  2825. }
  2826. HRESULT AddTermFunc(_ATL_TERMFUNC* pFunc, DWORD_PTR dw)
  2827. {
  2828. return AtlModuleAddTermFunc(this, pFunc, dw);
  2829. }
  2830. LONG Lock()
  2831. {
  2832. return CComGlobalsThreadModel::Increment(&m_nLockCnt);
  2833. }
  2834. LONG Unlock()
  2835. {
  2836. return CComGlobalsThreadModel::Decrement(&m_nLockCnt);
  2837. }
  2838. LONG GetLockCount()
  2839. {
  2840. return m_nLockCnt;
  2841. }
  2842. HINSTANCE GetModuleInstance() {return m_hInst;}
  2843. HINSTANCE GetResourceInstance() {return m_hInstResource;}
  2844. HINSTANCE GetTypeLibInstance() {return m_hInstTypeLib;}
  2845. // Registry support (helpers)
  2846. HRESULT RegisterTypeLib()
  2847. {
  2848. return AtlModuleRegisterTypeLib(this, NULL);
  2849. }
  2850. HRESULT RegisterTypeLib(LPCTSTR lpszIndex)
  2851. {
  2852. USES_CONVERSION;
  2853. return AtlModuleRegisterTypeLib(this, T2COLE(lpszIndex));
  2854. }
  2855. HRESULT UnRegisterTypeLib()
  2856. {
  2857. return AtlModuleUnRegisterTypeLib(this, NULL);
  2858. }
  2859. HRESULT UnRegisterTypeLib(LPCTSTR lpszIndex)
  2860. {
  2861. USES_CONVERSION;
  2862. return AtlModuleUnRegisterTypeLib(this, T2COLE(lpszIndex));
  2863. }
  2864. HRESULT RegisterServer(BOOL bRegTypeLib = FALSE, const CLSID* pCLSID = NULL)
  2865. {
  2866. return AtlModuleRegisterServer(this, bRegTypeLib, pCLSID);
  2867. }
  2868. HRESULT UnregisterServer(const CLSID* pCLSID = NULL)
  2869. {
  2870. return AtlModuleUnregisterServer(this, pCLSID);
  2871. }
  2872. HRESULT UnregisterServer(BOOL bUnRegTypeLib, const CLSID* pCLSID = NULL)
  2873. {
  2874. return AtlModuleUnregisterServerEx(this, bUnRegTypeLib, pCLSID);
  2875. }
  2876. // Resource-based Registration
  2877. HRESULT WINAPI UpdateRegistryFromResourceD(LPCTSTR lpszRes, BOOL bRegister,
  2878. struct _ATL_REGMAP_ENTRY* pMapEntries = NULL)
  2879. {
  2880. USES_CONVERSION;
  2881. return AtlModuleUpdateRegistryFromResourceD(this, T2COLE(lpszRes), bRegister,
  2882. pMapEntries);
  2883. }
  2884. HRESULT WINAPI UpdateRegistryFromResourceD(UINT nResID, BOOL bRegister,
  2885. struct _ATL_REGMAP_ENTRY* pMapEntries = NULL)
  2886. {
  2887. return AtlModuleUpdateRegistryFromResourceD(this,
  2888. (LPCOLESTR)MAKEINTRESOURCE(nResID), bRegister, pMapEntries);
  2889. }
  2890. #ifdef _ATL_STATIC_REGISTRY
  2891. // Statically linking to Registry Ponent
  2892. HRESULT WINAPI UpdateRegistryFromResourceS(LPCTSTR lpszRes, BOOL bRegister,
  2893. struct _ATL_REGMAP_ENTRY* pMapEntries = NULL);
  2894. HRESULT WINAPI UpdateRegistryFromResourceS(UINT nResID, BOOL bRegister,
  2895. struct _ATL_REGMAP_ENTRY* pMapEntries = NULL);
  2896. #endif
  2897. // Standard Registration
  2898. HRESULT WINAPI UpdateRegistryClass(const CLSID& clsid, LPCTSTR lpszProgID,
  2899. LPCTSTR lpszVerIndProgID, UINT nDescID, DWORD dwFlags, BOOL bRegister);
  2900. HRESULT WINAPI RegisterClassHelper(const CLSID& clsid, LPCTSTR lpszProgID,
  2901. LPCTSTR lpszVerIndProgID, UINT nDescID, DWORD dwFlags);
  2902. HRESULT WINAPI UnregisterClassHelper(const CLSID& clsid, LPCTSTR lpszProgID,
  2903. LPCTSTR lpszVerIndProgID);
  2904. // Register/Revoke All Class Factories with the OS (EXE only)
  2905. HRESULT RegisterClassObjects(DWORD dwClsContext, DWORD dwFlags)
  2906. {
  2907. return AtlModuleRegisterClassObjects(this, dwClsContext, dwFlags);
  2908. }
  2909. HRESULT RevokeClassObjects()
  2910. {
  2911. return AtlModuleRevokeClassObjects(this);
  2912. }
  2913. // Obtain a Class Factory (DLL only)
  2914. HRESULT GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  2915. {
  2916. return AtlModuleGetClassObject(this, rclsid, riid, ppv);
  2917. }
  2918. // Only used in CComAutoThreadModule
  2919. HRESULT CreateInstance(void* /*pfnCreateInstance*/, REFIID /*riid*/, void** /*ppvObj*/)
  2920. {
  2921. ATLASSERT(FALSE);
  2922. return E_NOTIMPL;
  2923. }
  2924. static HRESULT RegisterProgID(LPCTSTR lpszCLSID, LPCTSTR lpszProgID, LPCTSTR lpszUserDesc);
  2925. static void ReplaceSingleQuote(LPOLESTR lpDest, LPCOLESTR lp)
  2926. {
  2927. while (*lp)
  2928. {
  2929. *lpDest++ = *lp;
  2930. if (*lp == OLESTR('\''))
  2931. *lpDest++ = *lp;
  2932. lp++;
  2933. }
  2934. *lpDest = NULL;
  2935. }
  2936. };
  2937. #ifdef _ATL_DEBUG_INTERFACES
  2938. inline ULONG _QIThunk::Release()
  2939. {
  2940. if (bBreak)
  2941. DebugBreak();
  2942. ATLASSERT(m_dwRef > 0);
  2943. ULONG l = InterlockedDecrement(&m_dwRef);
  2944. ATLTRACE(_T("%d< "), m_dwRef);
  2945. AtlDumpIID(iid, lpszClassName, S_OK);
  2946. pUnk->Release();
  2947. if (l == 0 && !bNonAddRefThunk)
  2948. _pModule->DeleteThunk(this);
  2949. return l;
  2950. }
  2951. inline static void atlBadThunkCall()
  2952. {
  2953. ATLASSERT(FALSE && "Call through deleted thunk");
  2954. }
  2955. #ifdef _M_IX86
  2956. #define IMPL_THUNK(n)\
  2957. __declspec(naked) inline HRESULT _QIThunk::f##n()\
  2958. {\
  2959. __asm mov eax, [esp+4]\
  2960. __asm cmp dword ptr [eax+8], 0\
  2961. __asm jg goodref\
  2962. __asm call atlBadThunkCall\
  2963. __asm goodref:\
  2964. __asm mov eax, [esp+4]\
  2965. __asm mov eax, dword ptr [eax+4]\
  2966. __asm mov [esp+4], eax\
  2967. __asm mov eax, dword ptr [eax]\
  2968. __asm mov eax, dword ptr [eax+4*n]\
  2969. __asm jmp eax\
  2970. }
  2971. #else
  2972. #define IMPL_THUNK(x)
  2973. #endif
  2974. IMPL_THUNK(3)
  2975. IMPL_THUNK(4)
  2976. IMPL_THUNK(5)
  2977. IMPL_THUNK(6)
  2978. IMPL_THUNK(7)
  2979. IMPL_THUNK(8)
  2980. IMPL_THUNK(9)
  2981. IMPL_THUNK(10)
  2982. IMPL_THUNK(11)
  2983. IMPL_THUNK(12)
  2984. IMPL_THUNK(13)
  2985. IMPL_THUNK(14)
  2986. IMPL_THUNK(15)
  2987. IMPL_THUNK(16)
  2988. IMPL_THUNK(17)
  2989. IMPL_THUNK(18)
  2990. IMPL_THUNK(19)
  2991. IMPL_THUNK(20)
  2992. IMPL_THUNK(21)
  2993. IMPL_THUNK(22)
  2994. IMPL_THUNK(23)
  2995. IMPL_THUNK(24)
  2996. IMPL_THUNK(25)
  2997. IMPL_THUNK(26)
  2998. IMPL_THUNK(27)
  2999. IMPL_THUNK(28)
  3000. IMPL_THUNK(29)
  3001. IMPL_THUNK(30)
  3002. IMPL_THUNK(31)
  3003. IMPL_THUNK(32)
  3004. IMPL_THUNK(33)
  3005. IMPL_THUNK(34)
  3006. IMPL_THUNK(35)
  3007. IMPL_THUNK(36)
  3008. IMPL_THUNK(37)
  3009. IMPL_THUNK(38)
  3010. IMPL_THUNK(39)
  3011. IMPL_THUNK(40)
  3012. IMPL_THUNK(41)
  3013. IMPL_THUNK(42)
  3014. IMPL_THUNK(43)
  3015. IMPL_THUNK(44)
  3016. IMPL_THUNK(45)
  3017. IMPL_THUNK(46)
  3018. IMPL_THUNK(47)
  3019. IMPL_THUNK(48)
  3020. IMPL_THUNK(49)
  3021. IMPL_THUNK(50)
  3022. IMPL_THUNK(51)
  3023. IMPL_THUNK(52)
  3024. IMPL_THUNK(53)
  3025. IMPL_THUNK(54)
  3026. IMPL_THUNK(55)
  3027. IMPL_THUNK(56)
  3028. IMPL_THUNK(57)
  3029. IMPL_THUNK(58)
  3030. IMPL_THUNK(59)
  3031. IMPL_THUNK(60)
  3032. IMPL_THUNK(61)
  3033. IMPL_THUNK(62)
  3034. IMPL_THUNK(63)
  3035. IMPL_THUNK(64)
  3036. IMPL_THUNK(65)
  3037. IMPL_THUNK(66)
  3038. IMPL_THUNK(67)
  3039. IMPL_THUNK(68)
  3040. IMPL_THUNK(69)
  3041. IMPL_THUNK(70)
  3042. IMPL_THUNK(71)
  3043. IMPL_THUNK(72)
  3044. IMPL_THUNK(73)
  3045. IMPL_THUNK(74)
  3046. IMPL_THUNK(75)
  3047. IMPL_THUNK(76)
  3048. IMPL_THUNK(77)
  3049. IMPL_THUNK(78)
  3050. IMPL_THUNK(79)
  3051. IMPL_THUNK(80)
  3052. IMPL_THUNK(81)
  3053. IMPL_THUNK(82)
  3054. IMPL_THUNK(83)
  3055. IMPL_THUNK(84)
  3056. IMPL_THUNK(85)
  3057. IMPL_THUNK(86)
  3058. IMPL_THUNK(87)
  3059. IMPL_THUNK(88)
  3060. IMPL_THUNK(89)
  3061. IMPL_THUNK(90)
  3062. IMPL_THUNK(91)
  3063. IMPL_THUNK(92)
  3064. IMPL_THUNK(93)
  3065. IMPL_THUNK(94)
  3066. IMPL_THUNK(95)
  3067. IMPL_THUNK(96)
  3068. IMPL_THUNK(97)
  3069. IMPL_THUNK(98)
  3070. IMPL_THUNK(99)
  3071. IMPL_THUNK(100)
  3072. IMPL_THUNK(101)
  3073. IMPL_THUNK(102)
  3074. IMPL_THUNK(103)
  3075. IMPL_THUNK(104)
  3076. IMPL_THUNK(105)
  3077. IMPL_THUNK(106)
  3078. IMPL_THUNK(107)
  3079. IMPL_THUNK(108)
  3080. IMPL_THUNK(109)
  3081. IMPL_THUNK(110)
  3082. IMPL_THUNK(111)
  3083. IMPL_THUNK(112)
  3084. IMPL_THUNK(113)
  3085. IMPL_THUNK(114)
  3086. IMPL_THUNK(115)
  3087. IMPL_THUNK(116)
  3088. IMPL_THUNK(117)
  3089. IMPL_THUNK(118)
  3090. IMPL_THUNK(119)
  3091. IMPL_THUNK(120)
  3092. IMPL_THUNK(121)
  3093. IMPL_THUNK(122)
  3094. IMPL_THUNK(123)
  3095. IMPL_THUNK(124)
  3096. IMPL_THUNK(125)
  3097. IMPL_THUNK(126)
  3098. IMPL_THUNK(127)
  3099. IMPL_THUNK(128)
  3100. IMPL_THUNK(129)
  3101. IMPL_THUNK(130)
  3102. IMPL_THUNK(131)
  3103. IMPL_THUNK(132)
  3104. IMPL_THUNK(133)
  3105. IMPL_THUNK(134)
  3106. IMPL_THUNK(135)
  3107. IMPL_THUNK(136)
  3108. IMPL_THUNK(137)
  3109. IMPL_THUNK(138)
  3110. IMPL_THUNK(139)
  3111. IMPL_THUNK(140)
  3112. IMPL_THUNK(141)
  3113. IMPL_THUNK(142)
  3114. IMPL_THUNK(143)
  3115. IMPL_THUNK(144)
  3116. IMPL_THUNK(145)
  3117. IMPL_THUNK(146)
  3118. IMPL_THUNK(147)
  3119. IMPL_THUNK(148)
  3120. IMPL_THUNK(149)
  3121. IMPL_THUNK(150)
  3122. IMPL_THUNK(151)
  3123. IMPL_THUNK(152)
  3124. IMPL_THUNK(153)
  3125. IMPL_THUNK(154)
  3126. IMPL_THUNK(155)
  3127. IMPL_THUNK(156)
  3128. IMPL_THUNK(157)
  3129. IMPL_THUNK(158)
  3130. IMPL_THUNK(159)
  3131. IMPL_THUNK(160)
  3132. IMPL_THUNK(161)
  3133. IMPL_THUNK(162)
  3134. IMPL_THUNK(163)
  3135. IMPL_THUNK(164)
  3136. IMPL_THUNK(165)
  3137. IMPL_THUNK(166)
  3138. IMPL_THUNK(167)
  3139. IMPL_THUNK(168)
  3140. IMPL_THUNK(169)
  3141. IMPL_THUNK(170)
  3142. IMPL_THUNK(171)
  3143. IMPL_THUNK(172)
  3144. IMPL_THUNK(173)
  3145. IMPL_THUNK(174)
  3146. IMPL_THUNK(175)
  3147. IMPL_THUNK(176)
  3148. IMPL_THUNK(177)
  3149. IMPL_THUNK(178)
  3150. IMPL_THUNK(179)
  3151. IMPL_THUNK(180)
  3152. IMPL_THUNK(181)
  3153. IMPL_THUNK(182)
  3154. IMPL_THUNK(183)
  3155. IMPL_THUNK(184)
  3156. IMPL_THUNK(185)
  3157. IMPL_THUNK(186)
  3158. IMPL_THUNK(187)
  3159. IMPL_THUNK(188)
  3160. IMPL_THUNK(189)
  3161. IMPL_THUNK(190)
  3162. IMPL_THUNK(191)
  3163. IMPL_THUNK(192)
  3164. IMPL_THUNK(193)
  3165. IMPL_THUNK(194)
  3166. IMPL_THUNK(195)
  3167. IMPL_THUNK(196)
  3168. IMPL_THUNK(197)
  3169. IMPL_THUNK(198)
  3170. IMPL_THUNK(199)
  3171. IMPL_THUNK(200)
  3172. IMPL_THUNK(201)
  3173. IMPL_THUNK(202)
  3174. IMPL_THUNK(203)
  3175. IMPL_THUNK(204)
  3176. IMPL_THUNK(205)
  3177. IMPL_THUNK(206)
  3178. IMPL_THUNK(207)
  3179. IMPL_THUNK(208)
  3180. IMPL_THUNK(209)
  3181. IMPL_THUNK(210)
  3182. IMPL_THUNK(211)
  3183. IMPL_THUNK(212)
  3184. IMPL_THUNK(213)
  3185. IMPL_THUNK(214)
  3186. IMPL_THUNK(215)
  3187. IMPL_THUNK(216)
  3188. IMPL_THUNK(217)
  3189. IMPL_THUNK(218)
  3190. IMPL_THUNK(219)
  3191. IMPL_THUNK(220)
  3192. IMPL_THUNK(221)
  3193. IMPL_THUNK(222)
  3194. IMPL_THUNK(223)
  3195. IMPL_THUNK(224)
  3196. IMPL_THUNK(225)
  3197. IMPL_THUNK(226)
  3198. IMPL_THUNK(227)
  3199. IMPL_THUNK(228)
  3200. IMPL_THUNK(229)
  3201. IMPL_THUNK(230)
  3202. IMPL_THUNK(231)
  3203. IMPL_THUNK(232)
  3204. IMPL_THUNK(233)
  3205. IMPL_THUNK(234)
  3206. IMPL_THUNK(235)
  3207. IMPL_THUNK(236)
  3208. IMPL_THUNK(237)
  3209. IMPL_THUNK(238)
  3210. IMPL_THUNK(239)
  3211. IMPL_THUNK(240)
  3212. IMPL_THUNK(241)
  3213. IMPL_THUNK(242)
  3214. IMPL_THUNK(243)
  3215. IMPL_THUNK(244)
  3216. IMPL_THUNK(245)
  3217. IMPL_THUNK(246)
  3218. IMPL_THUNK(247)
  3219. IMPL_THUNK(248)
  3220. IMPL_THUNK(249)
  3221. IMPL_THUNK(250)
  3222. IMPL_THUNK(251)
  3223. IMPL_THUNK(252)
  3224. IMPL_THUNK(253)
  3225. IMPL_THUNK(254)
  3226. IMPL_THUNK(255)
  3227. IMPL_THUNK(256)
  3228. IMPL_THUNK(257)
  3229. IMPL_THUNK(258)
  3230. IMPL_THUNK(259)
  3231. IMPL_THUNK(260)
  3232. IMPL_THUNK(261)
  3233. IMPL_THUNK(262)
  3234. IMPL_THUNK(263)
  3235. IMPL_THUNK(264)
  3236. IMPL_THUNK(265)
  3237. IMPL_THUNK(266)
  3238. IMPL_THUNK(267)
  3239. IMPL_THUNK(268)
  3240. IMPL_THUNK(269)
  3241. IMPL_THUNK(270)
  3242. IMPL_THUNK(271)
  3243. IMPL_THUNK(272)
  3244. IMPL_THUNK(273)
  3245. IMPL_THUNK(274)
  3246. IMPL_THUNK(275)
  3247. IMPL_THUNK(276)
  3248. IMPL_THUNK(277)
  3249. IMPL_THUNK(278)
  3250. IMPL_THUNK(279)
  3251. IMPL_THUNK(280)
  3252. IMPL_THUNK(281)
  3253. IMPL_THUNK(282)
  3254. IMPL_THUNK(283)
  3255. IMPL_THUNK(284)
  3256. IMPL_THUNK(285)
  3257. IMPL_THUNK(286)
  3258. IMPL_THUNK(287)
  3259. IMPL_THUNK(288)
  3260. IMPL_THUNK(289)
  3261. IMPL_THUNK(290)
  3262. IMPL_THUNK(291)
  3263. IMPL_THUNK(292)
  3264. IMPL_THUNK(293)
  3265. IMPL_THUNK(294)
  3266. IMPL_THUNK(295)
  3267. IMPL_THUNK(296)
  3268. IMPL_THUNK(297)
  3269. IMPL_THUNK(298)
  3270. IMPL_THUNK(299)
  3271. IMPL_THUNK(300)
  3272. IMPL_THUNK(301)
  3273. IMPL_THUNK(302)
  3274. IMPL_THUNK(303)
  3275. IMPL_THUNK(304)
  3276. IMPL_THUNK(305)
  3277. IMPL_THUNK(306)
  3278. IMPL_THUNK(307)
  3279. IMPL_THUNK(308)
  3280. IMPL_THUNK(309)
  3281. IMPL_THUNK(310)
  3282. IMPL_THUNK(311)
  3283. IMPL_THUNK(312)
  3284. IMPL_THUNK(313)
  3285. IMPL_THUNK(314)
  3286. IMPL_THUNK(315)
  3287. IMPL_THUNK(316)
  3288. IMPL_THUNK(317)
  3289. IMPL_THUNK(318)
  3290. IMPL_THUNK(319)
  3291. IMPL_THUNK(320)
  3292. IMPL_THUNK(321)
  3293. IMPL_THUNK(322)
  3294. IMPL_THUNK(323)
  3295. IMPL_THUNK(324)
  3296. IMPL_THUNK(325)
  3297. IMPL_THUNK(326)
  3298. IMPL_THUNK(327)
  3299. IMPL_THUNK(328)
  3300. IMPL_THUNK(329)
  3301. IMPL_THUNK(330)
  3302. IMPL_THUNK(331)
  3303. IMPL_THUNK(332)
  3304. IMPL_THUNK(333)
  3305. IMPL_THUNK(334)
  3306. IMPL_THUNK(335)
  3307. IMPL_THUNK(336)
  3308. IMPL_THUNK(337)
  3309. IMPL_THUNK(338)
  3310. IMPL_THUNK(339)
  3311. IMPL_THUNK(340)
  3312. IMPL_THUNK(341)
  3313. IMPL_THUNK(342)
  3314. IMPL_THUNK(343)
  3315. IMPL_THUNK(344)
  3316. IMPL_THUNK(345)
  3317. IMPL_THUNK(346)
  3318. IMPL_THUNK(347)
  3319. IMPL_THUNK(348)
  3320. IMPL_THUNK(349)
  3321. IMPL_THUNK(350)
  3322. IMPL_THUNK(351)
  3323. IMPL_THUNK(352)
  3324. IMPL_THUNK(353)
  3325. IMPL_THUNK(354)
  3326. IMPL_THUNK(355)
  3327. IMPL_THUNK(356)
  3328. IMPL_THUNK(357)
  3329. IMPL_THUNK(358)
  3330. IMPL_THUNK(359)
  3331. IMPL_THUNK(360)
  3332. IMPL_THUNK(361)
  3333. IMPL_THUNK(362)
  3334. IMPL_THUNK(363)
  3335. IMPL_THUNK(364)
  3336. IMPL_THUNK(365)
  3337. IMPL_THUNK(366)
  3338. IMPL_THUNK(367)
  3339. IMPL_THUNK(368)
  3340. IMPL_THUNK(369)
  3341. IMPL_THUNK(370)
  3342. IMPL_THUNK(371)
  3343. IMPL_THUNK(372)
  3344. IMPL_THUNK(373)
  3345. IMPL_THUNK(374)
  3346. IMPL_THUNK(375)
  3347. IMPL_THUNK(376)
  3348. IMPL_THUNK(377)
  3349. IMPL_THUNK(378)
  3350. IMPL_THUNK(379)
  3351. IMPL_THUNK(380)
  3352. IMPL_THUNK(381)
  3353. IMPL_THUNK(382)
  3354. IMPL_THUNK(383)
  3355. IMPL_THUNK(384)
  3356. IMPL_THUNK(385)
  3357. IMPL_THUNK(386)
  3358. IMPL_THUNK(387)
  3359. IMPL_THUNK(388)
  3360. IMPL_THUNK(389)
  3361. IMPL_THUNK(390)
  3362. IMPL_THUNK(391)
  3363. IMPL_THUNK(392)
  3364. IMPL_THUNK(393)
  3365. IMPL_THUNK(394)
  3366. IMPL_THUNK(395)
  3367. IMPL_THUNK(396)
  3368. IMPL_THUNK(397)
  3369. IMPL_THUNK(398)
  3370. IMPL_THUNK(399)
  3371. IMPL_THUNK(400)
  3372. IMPL_THUNK(401)
  3373. IMPL_THUNK(402)
  3374. IMPL_THUNK(403)
  3375. IMPL_THUNK(404)
  3376. IMPL_THUNK(405)
  3377. IMPL_THUNK(406)
  3378. IMPL_THUNK(407)
  3379. IMPL_THUNK(408)
  3380. IMPL_THUNK(409)
  3381. IMPL_THUNK(410)
  3382. IMPL_THUNK(411)
  3383. IMPL_THUNK(412)
  3384. IMPL_THUNK(413)
  3385. IMPL_THUNK(414)
  3386. IMPL_THUNK(415)
  3387. IMPL_THUNK(416)
  3388. IMPL_THUNK(417)
  3389. IMPL_THUNK(418)
  3390. IMPL_THUNK(419)
  3391. IMPL_THUNK(420)
  3392. IMPL_THUNK(421)
  3393. IMPL_THUNK(422)
  3394. IMPL_THUNK(423)
  3395. IMPL_THUNK(424)
  3396. IMPL_THUNK(425)
  3397. IMPL_THUNK(426)
  3398. IMPL_THUNK(427)
  3399. IMPL_THUNK(428)
  3400. IMPL_THUNK(429)
  3401. IMPL_THUNK(430)
  3402. IMPL_THUNK(431)
  3403. IMPL_THUNK(432)
  3404. IMPL_THUNK(433)
  3405. IMPL_THUNK(434)
  3406. IMPL_THUNK(435)
  3407. IMPL_THUNK(436)
  3408. IMPL_THUNK(437)
  3409. IMPL_THUNK(438)
  3410. IMPL_THUNK(439)
  3411. IMPL_THUNK(440)
  3412. IMPL_THUNK(441)
  3413. IMPL_THUNK(442)
  3414. IMPL_THUNK(443)
  3415. IMPL_THUNK(444)
  3416. IMPL_THUNK(445)
  3417. IMPL_THUNK(446)
  3418. IMPL_THUNK(447)
  3419. IMPL_THUNK(448)
  3420. IMPL_THUNK(449)
  3421. IMPL_THUNK(450)
  3422. IMPL_THUNK(451)
  3423. IMPL_THUNK(452)
  3424. IMPL_THUNK(453)
  3425. IMPL_THUNK(454)
  3426. IMPL_THUNK(455)
  3427. IMPL_THUNK(456)
  3428. IMPL_THUNK(457)
  3429. IMPL_THUNK(458)
  3430. IMPL_THUNK(459)
  3431. IMPL_THUNK(460)
  3432. IMPL_THUNK(461)
  3433. IMPL_THUNK(462)
  3434. IMPL_THUNK(463)
  3435. IMPL_THUNK(464)
  3436. IMPL_THUNK(465)
  3437. IMPL_THUNK(466)
  3438. IMPL_THUNK(467)
  3439. IMPL_THUNK(468)
  3440. IMPL_THUNK(469)
  3441. IMPL_THUNK(470)
  3442. IMPL_THUNK(471)
  3443. IMPL_THUNK(472)
  3444. IMPL_THUNK(473)
  3445. IMPL_THUNK(474)
  3446. IMPL_THUNK(475)
  3447. IMPL_THUNK(476)
  3448. IMPL_THUNK(477)
  3449. IMPL_THUNK(478)
  3450. IMPL_THUNK(479)
  3451. IMPL_THUNK(480)
  3452. IMPL_THUNK(481)
  3453. IMPL_THUNK(482)
  3454. IMPL_THUNK(483)
  3455. IMPL_THUNK(484)
  3456. IMPL_THUNK(485)
  3457. IMPL_THUNK(486)
  3458. IMPL_THUNK(487)
  3459. IMPL_THUNK(488)
  3460. IMPL_THUNK(489)
  3461. IMPL_THUNK(490)
  3462. IMPL_THUNK(491)
  3463. IMPL_THUNK(492)
  3464. IMPL_THUNK(493)
  3465. IMPL_THUNK(494)
  3466. IMPL_THUNK(495)
  3467. IMPL_THUNK(496)
  3468. IMPL_THUNK(497)
  3469. IMPL_THUNK(498)
  3470. IMPL_THUNK(499)
  3471. IMPL_THUNK(500)
  3472. IMPL_THUNK(501)
  3473. IMPL_THUNK(502)
  3474. IMPL_THUNK(503)
  3475. IMPL_THUNK(504)
  3476. IMPL_THUNK(505)
  3477. IMPL_THUNK(506)
  3478. IMPL_THUNK(507)
  3479. IMPL_THUNK(508)
  3480. IMPL_THUNK(509)
  3481. IMPL_THUNK(510)
  3482. IMPL_THUNK(511)
  3483. IMPL_THUNK(512)
  3484. IMPL_THUNK(513)
  3485. IMPL_THUNK(514)
  3486. IMPL_THUNK(515)
  3487. IMPL_THUNK(516)
  3488. IMPL_THUNK(517)
  3489. IMPL_THUNK(518)
  3490. IMPL_THUNK(519)
  3491. IMPL_THUNK(520)
  3492. IMPL_THUNK(521)
  3493. IMPL_THUNK(522)
  3494. IMPL_THUNK(523)
  3495. IMPL_THUNK(524)
  3496. IMPL_THUNK(525)
  3497. IMPL_THUNK(526)
  3498. IMPL_THUNK(527)
  3499. IMPL_THUNK(528)
  3500. IMPL_THUNK(529)
  3501. IMPL_THUNK(530)
  3502. IMPL_THUNK(531)
  3503. IMPL_THUNK(532)
  3504. IMPL_THUNK(533)
  3505. IMPL_THUNK(534)
  3506. IMPL_THUNK(535)
  3507. IMPL_THUNK(536)
  3508. IMPL_THUNK(537)
  3509. IMPL_THUNK(538)
  3510. IMPL_THUNK(539)
  3511. IMPL_THUNK(540)
  3512. IMPL_THUNK(541)
  3513. IMPL_THUNK(542)
  3514. IMPL_THUNK(543)
  3515. IMPL_THUNK(544)
  3516. IMPL_THUNK(545)
  3517. IMPL_THUNK(546)
  3518. IMPL_THUNK(547)
  3519. IMPL_THUNK(548)
  3520. IMPL_THUNK(549)
  3521. IMPL_THUNK(550)
  3522. IMPL_THUNK(551)
  3523. IMPL_THUNK(552)
  3524. IMPL_THUNK(553)
  3525. IMPL_THUNK(554)
  3526. IMPL_THUNK(555)
  3527. IMPL_THUNK(556)
  3528. IMPL_THUNK(557)
  3529. IMPL_THUNK(558)
  3530. IMPL_THUNK(559)
  3531. IMPL_THUNK(560)
  3532. IMPL_THUNK(561)
  3533. IMPL_THUNK(562)
  3534. IMPL_THUNK(563)
  3535. IMPL_THUNK(564)
  3536. IMPL_THUNK(565)
  3537. IMPL_THUNK(566)
  3538. IMPL_THUNK(567)
  3539. IMPL_THUNK(568)
  3540. IMPL_THUNK(569)
  3541. IMPL_THUNK(570)
  3542. IMPL_THUNK(571)
  3543. IMPL_THUNK(572)
  3544. IMPL_THUNK(573)
  3545. IMPL_THUNK(574)
  3546. IMPL_THUNK(575)
  3547. IMPL_THUNK(576)
  3548. IMPL_THUNK(577)
  3549. IMPL_THUNK(578)
  3550. IMPL_THUNK(579)
  3551. IMPL_THUNK(580)
  3552. IMPL_THUNK(581)
  3553. IMPL_THUNK(582)
  3554. IMPL_THUNK(583)
  3555. IMPL_THUNK(584)
  3556. IMPL_THUNK(585)
  3557. IMPL_THUNK(586)
  3558. IMPL_THUNK(587)
  3559. IMPL_THUNK(588)
  3560. IMPL_THUNK(589)
  3561. IMPL_THUNK(590)
  3562. IMPL_THUNK(591)
  3563. IMPL_THUNK(592)
  3564. IMPL_THUNK(593)
  3565. IMPL_THUNK(594)
  3566. IMPL_THUNK(595)
  3567. IMPL_THUNK(596)
  3568. IMPL_THUNK(597)
  3569. IMPL_THUNK(598)
  3570. IMPL_THUNK(599)
  3571. IMPL_THUNK(600)
  3572. IMPL_THUNK(601)
  3573. IMPL_THUNK(602)
  3574. IMPL_THUNK(603)
  3575. IMPL_THUNK(604)
  3576. IMPL_THUNK(605)
  3577. IMPL_THUNK(606)
  3578. IMPL_THUNK(607)
  3579. IMPL_THUNK(608)
  3580. IMPL_THUNK(609)
  3581. IMPL_THUNK(610)
  3582. IMPL_THUNK(611)
  3583. IMPL_THUNK(612)
  3584. IMPL_THUNK(613)
  3585. IMPL_THUNK(614)
  3586. IMPL_THUNK(615)
  3587. IMPL_THUNK(616)
  3588. IMPL_THUNK(617)
  3589. IMPL_THUNK(618)
  3590. IMPL_THUNK(619)
  3591. IMPL_THUNK(620)
  3592. IMPL_THUNK(621)
  3593. IMPL_THUNK(622)
  3594. IMPL_THUNK(623)
  3595. IMPL_THUNK(624)
  3596. IMPL_THUNK(625)
  3597. IMPL_THUNK(626)
  3598. IMPL_THUNK(627)
  3599. IMPL_THUNK(628)
  3600. IMPL_THUNK(629)
  3601. IMPL_THUNK(630)
  3602. IMPL_THUNK(631)
  3603. IMPL_THUNK(632)
  3604. IMPL_THUNK(633)
  3605. IMPL_THUNK(634)
  3606. IMPL_THUNK(635)
  3607. IMPL_THUNK(636)
  3608. IMPL_THUNK(637)
  3609. IMPL_THUNK(638)
  3610. IMPL_THUNK(639)
  3611. IMPL_THUNK(640)
  3612. IMPL_THUNK(641)
  3613. IMPL_THUNK(642)
  3614. IMPL_THUNK(643)
  3615. IMPL_THUNK(644)
  3616. IMPL_THUNK(645)
  3617. IMPL_THUNK(646)
  3618. IMPL_THUNK(647)
  3619. IMPL_THUNK(648)
  3620. IMPL_THUNK(649)
  3621. IMPL_THUNK(650)
  3622. IMPL_THUNK(651)
  3623. IMPL_THUNK(652)
  3624. IMPL_THUNK(653)
  3625. IMPL_THUNK(654)
  3626. IMPL_THUNK(655)
  3627. IMPL_THUNK(656)
  3628. IMPL_THUNK(657)
  3629. IMPL_THUNK(658)
  3630. IMPL_THUNK(659)
  3631. IMPL_THUNK(660)
  3632. IMPL_THUNK(661)
  3633. IMPL_THUNK(662)
  3634. IMPL_THUNK(663)
  3635. IMPL_THUNK(664)
  3636. IMPL_THUNK(665)
  3637. IMPL_THUNK(666)
  3638. IMPL_THUNK(667)
  3639. IMPL_THUNK(668)
  3640. IMPL_THUNK(669)
  3641. IMPL_THUNK(670)
  3642. IMPL_THUNK(671)
  3643. IMPL_THUNK(672)
  3644. IMPL_THUNK(673)
  3645. IMPL_THUNK(674)
  3646. IMPL_THUNK(675)
  3647. IMPL_THUNK(676)
  3648. IMPL_THUNK(677)
  3649. IMPL_THUNK(678)
  3650. IMPL_THUNK(679)
  3651. IMPL_THUNK(680)
  3652. IMPL_THUNK(681)
  3653. IMPL_THUNK(682)
  3654. IMPL_THUNK(683)
  3655. IMPL_THUNK(684)
  3656. IMPL_THUNK(685)
  3657. IMPL_THUNK(686)
  3658. IMPL_THUNK(687)
  3659. IMPL_THUNK(688)
  3660. IMPL_THUNK(689)
  3661. IMPL_THUNK(690)
  3662. IMPL_THUNK(691)
  3663. IMPL_THUNK(692)
  3664. IMPL_THUNK(693)
  3665. IMPL_THUNK(694)
  3666. IMPL_THUNK(695)
  3667. IMPL_THUNK(696)
  3668. IMPL_THUNK(697)
  3669. IMPL_THUNK(698)
  3670. IMPL_THUNK(699)
  3671. IMPL_THUNK(700)
  3672. IMPL_THUNK(701)
  3673. IMPL_THUNK(702)
  3674. IMPL_THUNK(703)
  3675. IMPL_THUNK(704)
  3676. IMPL_THUNK(705)
  3677. IMPL_THUNK(706)
  3678. IMPL_THUNK(707)
  3679. IMPL_THUNK(708)
  3680. IMPL_THUNK(709)
  3681. IMPL_THUNK(710)
  3682. IMPL_THUNK(711)
  3683. IMPL_THUNK(712)
  3684. IMPL_THUNK(713)
  3685. IMPL_THUNK(714)
  3686. IMPL_THUNK(715)
  3687. IMPL_THUNK(716)
  3688. IMPL_THUNK(717)
  3689. IMPL_THUNK(718)
  3690. IMPL_THUNK(719)
  3691. IMPL_THUNK(720)
  3692. IMPL_THUNK(721)
  3693. IMPL_THUNK(722)
  3694. IMPL_THUNK(723)
  3695. IMPL_THUNK(724)
  3696. IMPL_THUNK(725)
  3697. IMPL_THUNK(726)
  3698. IMPL_THUNK(727)
  3699. IMPL_THUNK(728)
  3700. IMPL_THUNK(729)
  3701. IMPL_THUNK(730)
  3702. IMPL_THUNK(731)
  3703. IMPL_THUNK(732)
  3704. IMPL_THUNK(733)
  3705. IMPL_THUNK(734)
  3706. IMPL_THUNK(735)
  3707. IMPL_THUNK(736)
  3708. IMPL_THUNK(737)
  3709. IMPL_THUNK(738)
  3710. IMPL_THUNK(739)
  3711. IMPL_THUNK(740)
  3712. IMPL_THUNK(741)
  3713. IMPL_THUNK(742)
  3714. IMPL_THUNK(743)
  3715. IMPL_THUNK(744)
  3716. IMPL_THUNK(745)
  3717. IMPL_THUNK(746)
  3718. IMPL_THUNK(747)
  3719. IMPL_THUNK(748)
  3720. IMPL_THUNK(749)
  3721. IMPL_THUNK(750)
  3722. IMPL_THUNK(751)
  3723. IMPL_THUNK(752)
  3724. IMPL_THUNK(753)
  3725. IMPL_THUNK(754)
  3726. IMPL_THUNK(755)
  3727. IMPL_THUNK(756)
  3728. IMPL_THUNK(757)
  3729. IMPL_THUNK(758)
  3730. IMPL_THUNK(759)
  3731. IMPL_THUNK(760)
  3732. IMPL_THUNK(761)
  3733. IMPL_THUNK(762)
  3734. IMPL_THUNK(763)
  3735. IMPL_THUNK(764)
  3736. IMPL_THUNK(765)
  3737. IMPL_THUNK(766)
  3738. IMPL_THUNK(767)
  3739. IMPL_THUNK(768)
  3740. IMPL_THUNK(769)
  3741. IMPL_THUNK(770)
  3742. IMPL_THUNK(771)
  3743. IMPL_THUNK(772)
  3744. IMPL_THUNK(773)
  3745. IMPL_THUNK(774)
  3746. IMPL_THUNK(775)
  3747. IMPL_THUNK(776)
  3748. IMPL_THUNK(777)
  3749. IMPL_THUNK(778)
  3750. IMPL_THUNK(779)
  3751. IMPL_THUNK(780)
  3752. IMPL_THUNK(781)
  3753. IMPL_THUNK(782)
  3754. IMPL_THUNK(783)
  3755. IMPL_THUNK(784)
  3756. IMPL_THUNK(785)
  3757. IMPL_THUNK(786)
  3758. IMPL_THUNK(787)
  3759. IMPL_THUNK(788)
  3760. IMPL_THUNK(789)
  3761. IMPL_THUNK(790)
  3762. IMPL_THUNK(791)
  3763. IMPL_THUNK(792)
  3764. IMPL_THUNK(793)
  3765. IMPL_THUNK(794)
  3766. IMPL_THUNK(795)
  3767. IMPL_THUNK(796)
  3768. IMPL_THUNK(797)
  3769. IMPL_THUNK(798)
  3770. IMPL_THUNK(799)
  3771. IMPL_THUNK(800)
  3772. IMPL_THUNK(801)
  3773. IMPL_THUNK(802)
  3774. IMPL_THUNK(803)
  3775. IMPL_THUNK(804)
  3776. IMPL_THUNK(805)
  3777. IMPL_THUNK(806)
  3778. IMPL_THUNK(807)
  3779. IMPL_THUNK(808)
  3780. IMPL_THUNK(809)
  3781. IMPL_THUNK(810)
  3782. IMPL_THUNK(811)
  3783. IMPL_THUNK(812)
  3784. IMPL_THUNK(813)
  3785. IMPL_THUNK(814)
  3786. IMPL_THUNK(815)
  3787. IMPL_THUNK(816)
  3788. IMPL_THUNK(817)
  3789. IMPL_THUNK(818)
  3790. IMPL_THUNK(819)
  3791. IMPL_THUNK(820)
  3792. IMPL_THUNK(821)
  3793. IMPL_THUNK(822)
  3794. IMPL_THUNK(823)
  3795. IMPL_THUNK(824)
  3796. IMPL_THUNK(825)
  3797. IMPL_THUNK(826)
  3798. IMPL_THUNK(827)
  3799. IMPL_THUNK(828)
  3800. IMPL_THUNK(829)
  3801. IMPL_THUNK(830)
  3802. IMPL_THUNK(831)
  3803. IMPL_THUNK(832)
  3804. IMPL_THUNK(833)
  3805. IMPL_THUNK(834)
  3806. IMPL_THUNK(835)
  3807. IMPL_THUNK(836)
  3808. IMPL_THUNK(837)
  3809. IMPL_THUNK(838)
  3810. IMPL_THUNK(839)
  3811. IMPL_THUNK(840)
  3812. IMPL_THUNK(841)
  3813. IMPL_THUNK(842)
  3814. IMPL_THUNK(843)
  3815. IMPL_THUNK(844)
  3816. IMPL_THUNK(845)
  3817. IMPL_THUNK(846)
  3818. IMPL_THUNK(847)
  3819. IMPL_THUNK(848)
  3820. IMPL_THUNK(849)
  3821. IMPL_THUNK(850)
  3822. IMPL_THUNK(851)
  3823. IMPL_THUNK(852)
  3824. IMPL_THUNK(853)
  3825. IMPL_THUNK(854)
  3826. IMPL_THUNK(855)
  3827. IMPL_THUNK(856)
  3828. IMPL_THUNK(857)
  3829. IMPL_THUNK(858)
  3830. IMPL_THUNK(859)
  3831. IMPL_THUNK(860)
  3832. IMPL_THUNK(861)
  3833. IMPL_THUNK(862)
  3834. IMPL_THUNK(863)
  3835. IMPL_THUNK(864)
  3836. IMPL_THUNK(865)
  3837. IMPL_THUNK(866)
  3838. IMPL_THUNK(867)
  3839. IMPL_THUNK(868)
  3840. IMPL_THUNK(869)
  3841. IMPL_THUNK(870)
  3842. IMPL_THUNK(871)
  3843. IMPL_THUNK(872)
  3844. IMPL_THUNK(873)
  3845. IMPL_THUNK(874)
  3846. IMPL_THUNK(875)
  3847. IMPL_THUNK(876)
  3848. IMPL_THUNK(877)
  3849. IMPL_THUNK(878)
  3850. IMPL_THUNK(879)
  3851. IMPL_THUNK(880)
  3852. IMPL_THUNK(881)
  3853. IMPL_THUNK(882)
  3854. IMPL_THUNK(883)
  3855. IMPL_THUNK(884)
  3856. IMPL_THUNK(885)
  3857. IMPL_THUNK(886)
  3858. IMPL_THUNK(887)
  3859. IMPL_THUNK(888)
  3860. IMPL_THUNK(889)
  3861. IMPL_THUNK(890)
  3862. IMPL_THUNK(891)
  3863. IMPL_THUNK(892)
  3864. IMPL_THUNK(893)
  3865. IMPL_THUNK(894)
  3866. IMPL_THUNK(895)
  3867. IMPL_THUNK(896)
  3868. IMPL_THUNK(897)
  3869. IMPL_THUNK(898)
  3870. IMPL_THUNK(899)
  3871. IMPL_THUNK(900)
  3872. IMPL_THUNK(901)
  3873. IMPL_THUNK(902)
  3874. IMPL_THUNK(903)
  3875. IMPL_THUNK(904)
  3876. IMPL_THUNK(905)
  3877. IMPL_THUNK(906)
  3878. IMPL_THUNK(907)
  3879. IMPL_THUNK(908)
  3880. IMPL_THUNK(909)
  3881. IMPL_THUNK(910)
  3882. IMPL_THUNK(911)
  3883. IMPL_THUNK(912)
  3884. IMPL_THUNK(913)
  3885. IMPL_THUNK(914)
  3886. IMPL_THUNK(915)
  3887. IMPL_THUNK(916)
  3888. IMPL_THUNK(917)
  3889. IMPL_THUNK(918)
  3890. IMPL_THUNK(919)
  3891. IMPL_THUNK(920)
  3892. IMPL_THUNK(921)
  3893. IMPL_THUNK(922)
  3894. IMPL_THUNK(923)
  3895. IMPL_THUNK(924)
  3896. IMPL_THUNK(925)
  3897. IMPL_THUNK(926)
  3898. IMPL_THUNK(927)
  3899. IMPL_THUNK(928)
  3900. IMPL_THUNK(929)
  3901. IMPL_THUNK(930)
  3902. IMPL_THUNK(931)
  3903. IMPL_THUNK(932)
  3904. IMPL_THUNK(933)
  3905. IMPL_THUNK(934)
  3906. IMPL_THUNK(935)
  3907. IMPL_THUNK(936)
  3908. IMPL_THUNK(937)
  3909. IMPL_THUNK(938)
  3910. IMPL_THUNK(939)
  3911. IMPL_THUNK(940)
  3912. IMPL_THUNK(941)
  3913. IMPL_THUNK(942)
  3914. IMPL_THUNK(943)
  3915. IMPL_THUNK(944)
  3916. IMPL_THUNK(945)
  3917. IMPL_THUNK(946)
  3918. IMPL_THUNK(947)
  3919. IMPL_THUNK(948)
  3920. IMPL_THUNK(949)
  3921. IMPL_THUNK(950)
  3922. IMPL_THUNK(951)
  3923. IMPL_THUNK(952)
  3924. IMPL_THUNK(953)
  3925. IMPL_THUNK(954)
  3926. IMPL_THUNK(955)
  3927. IMPL_THUNK(956)
  3928. IMPL_THUNK(957)
  3929. IMPL_THUNK(958)
  3930. IMPL_THUNK(959)
  3931. IMPL_THUNK(960)
  3932. IMPL_THUNK(961)
  3933. IMPL_THUNK(962)
  3934. IMPL_THUNK(963)
  3935. IMPL_THUNK(964)
  3936. IMPL_THUNK(965)
  3937. IMPL_THUNK(966)
  3938. IMPL_THUNK(967)
  3939. IMPL_THUNK(968)
  3940. IMPL_THUNK(969)
  3941. IMPL_THUNK(970)
  3942. IMPL_THUNK(971)
  3943. IMPL_THUNK(972)
  3944. IMPL_THUNK(973)
  3945. IMPL_THUNK(974)
  3946. IMPL_THUNK(975)
  3947. IMPL_THUNK(976)
  3948. IMPL_THUNK(977)
  3949. IMPL_THUNK(978)
  3950. IMPL_THUNK(979)
  3951. IMPL_THUNK(980)
  3952. IMPL_THUNK(981)
  3953. IMPL_THUNK(982)
  3954. IMPL_THUNK(983)
  3955. IMPL_THUNK(984)
  3956. IMPL_THUNK(985)
  3957. IMPL_THUNK(986)
  3958. IMPL_THUNK(987)
  3959. IMPL_THUNK(988)
  3960. IMPL_THUNK(989)
  3961. IMPL_THUNK(990)
  3962. IMPL_THUNK(991)
  3963. IMPL_THUNK(992)
  3964. IMPL_THUNK(993)
  3965. IMPL_THUNK(994)
  3966. IMPL_THUNK(995)
  3967. IMPL_THUNK(996)
  3968. IMPL_THUNK(997)
  3969. IMPL_THUNK(998)
  3970. IMPL_THUNK(999)
  3971. IMPL_THUNK(1000)
  3972. IMPL_THUNK(1001)
  3973. IMPL_THUNK(1002)
  3974. IMPL_THUNK(1003)
  3975. IMPL_THUNK(1004)
  3976. IMPL_THUNK(1005)
  3977. IMPL_THUNK(1006)
  3978. IMPL_THUNK(1007)
  3979. IMPL_THUNK(1008)
  3980. IMPL_THUNK(1009)
  3981. IMPL_THUNK(1010)
  3982. IMPL_THUNK(1011)
  3983. IMPL_THUNK(1012)
  3984. IMPL_THUNK(1013)
  3985. IMPL_THUNK(1014)
  3986. IMPL_THUNK(1015)
  3987. IMPL_THUNK(1016)
  3988. IMPL_THUNK(1017)
  3989. IMPL_THUNK(1018)
  3990. IMPL_THUNK(1019)
  3991. IMPL_THUNK(1020)
  3992. IMPL_THUNK(1021)
  3993. IMPL_THUNK(1022)
  3994. IMPL_THUNK(1023)
  3995. IMPL_THUNK(1024)
  3996. #endif
  3997. __declspec(selectany) GUID CComModule::m_libid = {0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}};
  3998. #ifdef _ATL_STATIC_REGISTRY
  3999. #define UpdateRegistryFromResource UpdateRegistryFromResourceS
  4000. #else
  4001. #define UpdateRegistryFromResource UpdateRegistryFromResourceD
  4002. #endif
  4003. /////////////////////////////////////////////////////////////////////////////////////////////
  4004. // Thread Pooling classes
  4005. class _AtlAptCreateObjData
  4006. {
  4007. public:
  4008. _ATL_CREATORFUNC* pfnCreateInstance;
  4009. const IID* piid;
  4010. HANDLE hEvent;
  4011. LPSTREAM pStream;
  4012. HRESULT hRes;
  4013. };
  4014. class CComApartment
  4015. {
  4016. public:
  4017. CComApartment()
  4018. {
  4019. m_nLockCnt = 0;
  4020. }
  4021. static UINT ATL_CREATE_OBJECT;
  4022. static DWORD WINAPI _Apartment(void* pv)
  4023. {
  4024. return ((CComApartment*)pv)->Apartment();
  4025. }
  4026. DWORD Apartment()
  4027. {
  4028. CoInitialize(NULL);
  4029. MSG msg;
  4030. while(GetMessage(&msg, 0, 0, 0))
  4031. {
  4032. if (msg.message == ATL_CREATE_OBJECT)
  4033. {
  4034. _AtlAptCreateObjData* pdata = (_AtlAptCreateObjData*)msg.lParam;
  4035. IUnknown* pUnk = NULL;
  4036. pdata->hRes = pdata->pfnCreateInstance(NULL, IID_IUnknown, (void**)&pUnk);
  4037. if (SUCCEEDED(pdata->hRes))
  4038. pdata->hRes = CoMarshalInterThreadInterfaceInStream(*pdata->piid, pUnk, &pdata->pStream);
  4039. if (SUCCEEDED(pdata->hRes))
  4040. {
  4041. pUnk->Release();
  4042. ATLTRACE2(atlTraceCOM, 2, _T("Object created on thread = %d\n"), GetCurrentThreadId());
  4043. }
  4044. SetEvent(pdata->hEvent);
  4045. }
  4046. DispatchMessage(&msg);
  4047. }
  4048. CoUninitialize();
  4049. return 0;
  4050. }
  4051. LONG Lock() {return CComGlobalsThreadModel::Increment(&m_nLockCnt);}
  4052. LONG Unlock(){return CComGlobalsThreadModel::Decrement(&m_nLockCnt);
  4053. }
  4054. LONG GetLockCount() {return m_nLockCnt;}
  4055. DWORD m_dwThreadID;
  4056. HANDLE m_hThread;
  4057. LONG m_nLockCnt;
  4058. };
  4059. __declspec(selectany) UINT CComApartment::ATL_CREATE_OBJECT = 0;
  4060. class CComSimpleThreadAllocator
  4061. {
  4062. public:
  4063. CComSimpleThreadAllocator()
  4064. {
  4065. m_nThread = 0;
  4066. }
  4067. int GetThread(CComApartment* /*pApt*/, int nThreads)
  4068. {
  4069. if (++m_nThread == nThreads)
  4070. m_nThread = 0;
  4071. return m_nThread;
  4072. }
  4073. int m_nThread;
  4074. };
  4075. template <class ThreadAllocator = CComSimpleThreadAllocator>
  4076. class CComAutoThreadModule : public CComModule
  4077. {
  4078. public:
  4079. HRESULT Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, const GUID* plibid = NULL, int nThreads = GetDefaultThreads());
  4080. ~CComAutoThreadModule();
  4081. HRESULT CreateInstance(void* pfnCreateInstance, REFIID riid, void** ppvObj);
  4082. LONG Lock();
  4083. LONG Unlock();
  4084. DWORD dwThreadID;
  4085. int m_nThreads;
  4086. CComApartment* m_pApartments;
  4087. ThreadAllocator m_Allocator;
  4088. static int GetDefaultThreads()
  4089. {
  4090. SYSTEM_INFO si;
  4091. GetSystemInfo(&si);
  4092. return si.dwNumberOfProcessors * 4;
  4093. }
  4094. };
  4095. /////////////////////////////////////////////////////////////////////////////
  4096. // CComBSTR
  4097. class CComBSTR
  4098. {
  4099. public:
  4100. BSTR m_str;
  4101. CComBSTR()
  4102. {
  4103. m_str = NULL;
  4104. }
  4105. /*explicit*/ CComBSTR(int nSize)
  4106. {
  4107. m_str = ::SysAllocStringLen(NULL, nSize);
  4108. }
  4109. /*explicit*/ CComBSTR(int nSize, LPCOLESTR sz)
  4110. {
  4111. m_str = ::SysAllocStringLen(sz, nSize);
  4112. }
  4113. /*explicit*/ CComBSTR(LPCOLESTR pSrc)
  4114. {
  4115. m_str = ::SysAllocString(pSrc);
  4116. }
  4117. /*explicit*/ CComBSTR(const CComBSTR& src)
  4118. {
  4119. m_str = src.Copy();
  4120. }
  4121. /*explicit*/ CComBSTR(const BSTR* psrc)
  4122. {
  4123. if (!psrc) {
  4124. m_str = NULL;
  4125. } else {
  4126. m_str = ::SysAllocStringByteLen(reinterpret_cast<LPCSTR>(*psrc), ::SysStringByteLen(*psrc));
  4127. }
  4128. }
  4129. /*explicit*/ CComBSTR(REFGUID src)
  4130. {
  4131. LPOLESTR szGuid;
  4132. StringFromCLSID(src, &szGuid);
  4133. m_str = ::SysAllocString(szGuid);
  4134. CoTaskMemFree(szGuid);
  4135. }
  4136. CComBSTR& operator=(const CComBSTR& src)
  4137. {
  4138. if (m_str != src.m_str)
  4139. {
  4140. if (m_str)
  4141. ::SysFreeString(m_str);
  4142. m_str = src.Copy();
  4143. }
  4144. return *this;
  4145. }
  4146. CComBSTR& operator=(const BSTR* psrc)
  4147. {
  4148. if (!psrc) {
  4149. if (m_str)
  4150. ::SysFreeString(m_str);
  4151. m_str = NULL;
  4152. } else if (*psrc != m_str) {
  4153. if (m_str)
  4154. ::SysFreeString(m_str);
  4155. m_str = ::SysAllocStringByteLen(reinterpret_cast<LPCSTR>(*psrc), ::SysStringByteLen(*psrc));
  4156. }
  4157. return *this;
  4158. }
  4159. CComBSTR& operator=(LPCOLESTR pSrc)
  4160. {
  4161. ::SysFreeString(m_str);
  4162. m_str = ::SysAllocString(pSrc);
  4163. return *this;
  4164. }
  4165. ~CComBSTR()
  4166. {
  4167. ::SysFreeString(m_str);
  4168. }
  4169. unsigned int Length() const
  4170. {
  4171. return (m_str == NULL)? 0 : SysStringLen(m_str);
  4172. }
  4173. operator BSTR() const
  4174. {
  4175. return m_str;
  4176. }
  4177. BSTR* operator&()
  4178. {
  4179. return &m_str;
  4180. }
  4181. BSTR Copy() const
  4182. {
  4183. return ::SysAllocStringLen(m_str, ::SysStringLen(m_str));
  4184. }
  4185. HRESULT CopyTo(BSTR* pbstr)
  4186. {
  4187. // there should either be a runtime check or an assert(not both). otherwise
  4188. // we can't depend on the runtime check during unattended api tests and have to
  4189. // place a redundant extra check outside the call to CopyTo to keep assert
  4190. // dialogs from popping up
  4191. // ATLASSERT(pbstr != NULL);
  4192. if (pbstr == NULL)
  4193. return E_POINTER;
  4194. *pbstr = ::SysAllocStringLen(m_str, ::SysStringLen(m_str));
  4195. if (*pbstr == NULL)
  4196. return E_OUTOFMEMORY;
  4197. return S_OK;
  4198. }
  4199. void Attach(BSTR src)
  4200. {
  4201. ATLASSERT(m_str == NULL);
  4202. m_str = src;
  4203. }
  4204. BSTR Detach()
  4205. {
  4206. BSTR s = m_str;
  4207. m_str = NULL;
  4208. return s;
  4209. }
  4210. void Empty()
  4211. {
  4212. ::SysFreeString(m_str);
  4213. m_str = NULL;
  4214. }
  4215. bool operator!() const
  4216. {
  4217. return (m_str == NULL);
  4218. }
  4219. HRESULT Append(const CComBSTR& bstrSrc)
  4220. {
  4221. return Append(bstrSrc.m_str, SysStringLen(bstrSrc.m_str));
  4222. }
  4223. HRESULT Append(LPCOLESTR lpsz)
  4224. {
  4225. return Append(lpsz, ocslen(lpsz));
  4226. }
  4227. // a BSTR is just a LPCOLESTR so we need a special version to signify
  4228. // that we are appending a BSTR
  4229. HRESULT AppendBSTR(BSTR p)
  4230. {
  4231. return Append(p, SysStringLen(p));
  4232. }
  4233. HRESULT Append(LPCOLESTR lpsz, int nLen)
  4234. {
  4235. int n1 = Length();
  4236. BSTR b;
  4237. b = ::SysAllocStringLen(NULL, n1+nLen);
  4238. if (b == NULL)
  4239. return E_OUTOFMEMORY;
  4240. memcpy(b, m_str, n1*sizeof(OLECHAR));
  4241. memcpy(b+n1, lpsz, nLen*sizeof(OLECHAR));
  4242. b[n1+nLen] = NULL;
  4243. SysFreeString(m_str);
  4244. m_str = b;
  4245. return S_OK;
  4246. }
  4247. HRESULT ToLower()
  4248. {
  4249. USES_CONVERSION;
  4250. if (m_str != NULL)
  4251. {
  4252. LPTSTR psz = CharLower(OLE2T(m_str));
  4253. if (psz == NULL)
  4254. return E_OUTOFMEMORY;
  4255. BSTR b = T2BSTR(psz);
  4256. if (psz == NULL)
  4257. return E_OUTOFMEMORY;
  4258. SysFreeString(m_str);
  4259. m_str = b;
  4260. }
  4261. return S_OK;
  4262. }
  4263. HRESULT ToUpper()
  4264. {
  4265. USES_CONVERSION;
  4266. if (m_str != NULL)
  4267. {
  4268. LPTSTR psz = CharUpper(OLE2T(m_str));
  4269. if (psz == NULL)
  4270. return E_OUTOFMEMORY;
  4271. BSTR b = T2BSTR(psz);
  4272. if (psz == NULL)
  4273. return E_OUTOFMEMORY;
  4274. SysFreeString(m_str);
  4275. m_str = b;
  4276. }
  4277. return S_OK;
  4278. }
  4279. bool LoadString(HINSTANCE hInst, UINT nID)
  4280. {
  4281. USES_CONVERSION;
  4282. TCHAR sz[512];
  4283. UINT nLen = ::LoadString(hInst, nID, sz, 512);
  4284. ATLASSERT(nLen < 511);
  4285. SysFreeString(m_str);
  4286. m_str = (nLen != 0) ? SysAllocString(T2OLE(sz)) : NULL;
  4287. return (nLen != 0);
  4288. }
  4289. bool LoadString(UINT nID)
  4290. {
  4291. return LoadString(_pModule->m_hInstResource, nID);
  4292. }
  4293. CComBSTR& operator+=(const CComBSTR& bstrSrc)
  4294. {
  4295. AppendBSTR(bstrSrc.m_str);
  4296. return *this;
  4297. }
  4298. bool operator<(BSTR bstrSrc) const
  4299. {
  4300. if (bstrSrc == NULL && m_str == NULL)
  4301. return false;
  4302. if (bstrSrc != NULL && m_str != NULL)
  4303. return wcscmp(m_str, bstrSrc) < 0;
  4304. return m_str == NULL;
  4305. }
  4306. bool operator==(BSTR bstrSrc) const
  4307. {
  4308. if (bstrSrc == NULL && m_str == NULL)
  4309. return true;
  4310. if (bstrSrc != NULL && m_str != NULL)
  4311. return wcscmp(m_str, bstrSrc) == 0;
  4312. return false;
  4313. }
  4314. bool operator<(LPCSTR pszSrc) const
  4315. {
  4316. if (pszSrc == NULL && m_str == NULL)
  4317. return false;
  4318. USES_CONVERSION;
  4319. if (pszSrc != NULL && m_str != NULL)
  4320. return wcscmp(m_str, A2W(pszSrc)) < 0;
  4321. return m_str == NULL;
  4322. }
  4323. bool operator==(LPCSTR pszSrc) const
  4324. {
  4325. if (pszSrc == NULL && m_str == NULL)
  4326. return true;
  4327. USES_CONVERSION;
  4328. if (pszSrc != NULL && m_str != NULL)
  4329. return wcscmp(m_str, A2W(pszSrc)) == 0;
  4330. return false;
  4331. }
  4332. #ifndef OLE2ANSI
  4333. CComBSTR(LPCSTR pSrc)
  4334. {
  4335. m_str = A2WBSTR(pSrc);
  4336. }
  4337. CComBSTR(int nSize, LPCSTR sz)
  4338. {
  4339. m_str = A2WBSTR(sz, nSize);
  4340. }
  4341. void Append(LPCSTR lpsz)
  4342. {
  4343. USES_CONVERSION;
  4344. LPCOLESTR lpo = A2COLE(lpsz);
  4345. Append(lpo, ocslen(lpo));
  4346. }
  4347. CComBSTR& operator=(LPCSTR pSrc)
  4348. {
  4349. ::SysFreeString(m_str);
  4350. m_str = A2WBSTR(pSrc);
  4351. return *this;
  4352. }
  4353. #endif
  4354. HRESULT WriteToStream(IStream* pStream)
  4355. {
  4356. ATLASSERT(pStream != NULL);
  4357. ULONG cb;
  4358. ULONG cbStrLen = m_str ? SysStringByteLen(m_str)+sizeof(OLECHAR) : 0;
  4359. HRESULT hr = pStream->Write((void*) &cbStrLen, sizeof(cbStrLen), &cb);
  4360. if (FAILED(hr))
  4361. return hr;
  4362. return cbStrLen ? pStream->Write((void*) m_str, cbStrLen, &cb) : S_OK;
  4363. }
  4364. HRESULT ReadFromStream(IStream* pStream)
  4365. {
  4366. ATLASSERT(pStream != NULL);
  4367. ATLASSERT(m_str == NULL); // should be empty
  4368. ULONG cbStrLen = 0;
  4369. HRESULT hr = pStream->Read((void*) &cbStrLen, sizeof(cbStrLen), NULL);
  4370. if ((hr == S_OK) && (cbStrLen != 0))
  4371. {
  4372. //subtract size for terminating NULL which we wrote out
  4373. //since SysAllocStringByteLen overallocates for the NULL
  4374. m_str = SysAllocStringByteLen(NULL, cbStrLen-sizeof(OLECHAR));
  4375. if (m_str == NULL)
  4376. hr = E_OUTOFMEMORY;
  4377. else
  4378. hr = pStream->Read((void*) m_str, cbStrLen, NULL);
  4379. }
  4380. if (hr == S_FALSE)
  4381. hr = E_FAIL;
  4382. return hr;
  4383. }
  4384. // this allows direct use in stl containers
  4385. // without using the CAdapt template which causes extra addrefs/releases
  4386. // usage:
  4387. // std::vector<CComBSTR, CComBSTR::stl_allocator>
  4388. CComBSTR * address(void) { return this; }
  4389. const CComBSTR * const_address(void) const { return this; }
  4390. typedef stl_smart_ptr_allocator<CComBSTR> stl_allocator;
  4391. };
  4392. /////////////////////////////////////////////////////////////////////////////
  4393. // CComVariant
  4394. class CComVariant : public tagVARIANT
  4395. {
  4396. // Constructors
  4397. public:
  4398. CComVariant()
  4399. {
  4400. // ideally, we'd use ::VariantInit() here. but, it doesn't do anything but
  4401. // set the tag to VT_EMPTY. we must zero out the struct, otherwise there
  4402. // are cases where we set the tag to something non-empty in order to specify the
  4403. // right type to read from a property bag and if there's an error we autodestruct
  4404. // going out of scope and end up calling ::VariantClear with garbage which causes
  4405. // random crashes
  4406. memset(this, 0, sizeof(*this)); // safe since we're a pods
  4407. vt = VT_EMPTY;
  4408. }
  4409. ~CComVariant()
  4410. {
  4411. Clear();
  4412. }
  4413. CComVariant(const VARIANT& varSrc)
  4414. {
  4415. vt = VT_EMPTY;
  4416. InternalCopy(&varSrc);
  4417. }
  4418. CComVariant(const CComVariant& varSrc)
  4419. {
  4420. vt = VT_EMPTY;
  4421. InternalCopy(&varSrc);
  4422. }
  4423. CComVariant(BSTR bstrSrc)
  4424. {
  4425. vt = VT_EMPTY;
  4426. *this = bstrSrc;
  4427. }
  4428. CComVariant(LPCOLESTR lpszSrc)
  4429. {
  4430. vt = VT_EMPTY;
  4431. *this = lpszSrc;
  4432. }
  4433. #ifndef OLE2ANSI
  4434. CComVariant(LPCSTR lpszSrc)
  4435. {
  4436. vt = VT_EMPTY;
  4437. *this = lpszSrc;
  4438. }
  4439. #endif
  4440. CComVariant(bool bSrc)
  4441. {
  4442. vt = VT_BOOL;
  4443. #pragma warning(disable: 4310) // cast truncates constant value
  4444. boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
  4445. #pragma warning(default: 4310) // cast truncates constant value
  4446. }
  4447. CComVariant(int nSrc)
  4448. {
  4449. vt = VT_I4;
  4450. lVal = nSrc;
  4451. }
  4452. CComVariant(BYTE nSrc)
  4453. {
  4454. vt = VT_UI1;
  4455. bVal = nSrc;
  4456. }
  4457. CComVariant(short nSrc)
  4458. {
  4459. vt = VT_I2;
  4460. iVal = nSrc;
  4461. }
  4462. CComVariant(long nSrc, VARTYPE vtSrc = VT_I4)
  4463. {
  4464. ATLASSERT(vtSrc == VT_I4 || vtSrc == VT_ERROR);
  4465. vt = vtSrc;
  4466. lVal = nSrc;
  4467. }
  4468. CComVariant(float fltSrc)
  4469. {
  4470. vt = VT_R4;
  4471. fltVal = fltSrc;
  4472. }
  4473. CComVariant(double dblSrc)
  4474. {
  4475. vt = VT_R8;
  4476. dblVal = dblSrc;
  4477. }
  4478. CComVariant(CY cySrc)
  4479. {
  4480. vt = VT_CY;
  4481. cyVal.Hi = cySrc.Hi;
  4482. cyVal.Lo = cySrc.Lo;
  4483. }
  4484. CComVariant(IDispatch* pSrc)
  4485. {
  4486. vt = VT_DISPATCH;
  4487. pdispVal = pSrc;
  4488. // Need to AddRef as VariantClear will Release
  4489. if (pdispVal != NULL)
  4490. pdispVal->AddRef();
  4491. }
  4492. CComVariant(IUnknown* pSrc)
  4493. {
  4494. vt = VT_UNKNOWN;
  4495. punkVal = pSrc;
  4496. // Need to AddRef as VariantClear will Release
  4497. if (punkVal != NULL)
  4498. punkVal->AddRef();
  4499. }
  4500. CComVariant(SHORT* pSrc)
  4501. {
  4502. vt = VT_I2 | VT_BYREF;
  4503. piVal = pSrc;
  4504. }
  4505. // Assignment Operators
  4506. public:
  4507. CComVariant& operator=(const CComVariant& varSrc)
  4508. {
  4509. InternalCopy(&varSrc);
  4510. return *this;
  4511. }
  4512. CComVariant& operator=(const VARIANT& varSrc)
  4513. {
  4514. InternalCopy(&varSrc);
  4515. return *this;
  4516. }
  4517. CComVariant& operator=(BSTR bstrSrc)
  4518. {
  4519. InternalClear();
  4520. vt = VT_BSTR;
  4521. bstrVal = ::SysAllocString(bstrSrc);
  4522. if (bstrVal == NULL && bstrSrc != NULL)
  4523. {
  4524. vt = VT_ERROR;
  4525. scode = E_OUTOFMEMORY;
  4526. }
  4527. return *this;
  4528. }
  4529. CComVariant& operator=(LPCOLESTR lpszSrc)
  4530. {
  4531. InternalClear();
  4532. vt = VT_BSTR;
  4533. bstrVal = ::SysAllocString(lpszSrc);
  4534. if (bstrVal == NULL && lpszSrc != NULL)
  4535. {
  4536. vt = VT_ERROR;
  4537. scode = E_OUTOFMEMORY;
  4538. }
  4539. return *this;
  4540. }
  4541. #ifndef OLE2ANSI
  4542. CComVariant& operator=(LPCSTR lpszSrc)
  4543. {
  4544. USES_CONVERSION;
  4545. InternalClear();
  4546. vt = VT_BSTR;
  4547. bstrVal = ::SysAllocString(A2COLE(lpszSrc));
  4548. if (bstrVal == NULL && lpszSrc != NULL)
  4549. {
  4550. vt = VT_ERROR;
  4551. scode = E_OUTOFMEMORY;
  4552. }
  4553. return *this;
  4554. }
  4555. #endif
  4556. CComVariant& operator=(bool bSrc)
  4557. {
  4558. if (vt != VT_BOOL)
  4559. {
  4560. InternalClear();
  4561. vt = VT_BOOL;
  4562. }
  4563. #pragma warning(disable: 4310) // cast truncates constant value
  4564. boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
  4565. #pragma warning(default: 4310) // cast truncates constant value
  4566. return *this;
  4567. }
  4568. CComVariant& operator=(int nSrc)
  4569. {
  4570. if (vt != VT_I4)
  4571. {
  4572. InternalClear();
  4573. vt = VT_I4;
  4574. }
  4575. lVal = nSrc;
  4576. return *this;
  4577. }
  4578. CComVariant& operator=(BYTE nSrc)
  4579. {
  4580. if (vt != VT_UI1)
  4581. {
  4582. InternalClear();
  4583. vt = VT_UI1;
  4584. }
  4585. bVal = nSrc;
  4586. return *this;
  4587. }
  4588. CComVariant& operator=(short nSrc)
  4589. {
  4590. if (vt != VT_I2)
  4591. {
  4592. InternalClear();
  4593. vt = VT_I2;
  4594. }
  4595. iVal = nSrc;
  4596. return *this;
  4597. }
  4598. CComVariant& operator=(long nSrc)
  4599. {
  4600. if (vt != VT_I4)
  4601. {
  4602. InternalClear();
  4603. vt = VT_I4;
  4604. }
  4605. lVal = nSrc;
  4606. return *this;
  4607. }
  4608. CComVariant& operator=(float fltSrc)
  4609. {
  4610. if (vt != VT_R4)
  4611. {
  4612. InternalClear();
  4613. vt = VT_R4;
  4614. }
  4615. fltVal = fltSrc;
  4616. return *this;
  4617. }
  4618. CComVariant& operator=(double dblSrc)
  4619. {
  4620. if (vt != VT_R8)
  4621. {
  4622. InternalClear();
  4623. vt = VT_R8;
  4624. }
  4625. dblVal = dblSrc;
  4626. return *this;
  4627. }
  4628. CComVariant& operator=(CY cySrc)
  4629. {
  4630. if (vt != VT_CY)
  4631. {
  4632. InternalClear();
  4633. vt = VT_CY;
  4634. }
  4635. cyVal.Hi = cySrc.Hi;
  4636. cyVal.Lo = cySrc.Lo;
  4637. return *this;
  4638. }
  4639. CComVariant& operator=(IDispatch* pSrc)
  4640. {
  4641. InternalClear();
  4642. vt = VT_DISPATCH;
  4643. pdispVal = pSrc;
  4644. // Need to AddRef as VariantClear will Release
  4645. if (pdispVal != NULL)
  4646. pdispVal->AddRef();
  4647. return *this;
  4648. }
  4649. CComVariant& operator=(IUnknown* pSrc)
  4650. {
  4651. InternalClear();
  4652. vt = VT_UNKNOWN;
  4653. punkVal = pSrc;
  4654. // Need to AddRef as VariantClear will Release
  4655. if (punkVal != NULL)
  4656. punkVal->AddRef();
  4657. return *this;
  4658. }
  4659. CComVariant& operator=(SHORT* pSrc)
  4660. {
  4661. vt = VT_I2 | VT_BYREF;
  4662. piVal = pSrc;
  4663. return *this;
  4664. }
  4665. // Comparison Operators
  4666. public:
  4667. bool operator==(const VARIANT& varSrc) const
  4668. {
  4669. if (this == &varSrc)
  4670. return true;
  4671. // Variants not equal if types don't match
  4672. if (vt != varSrc.vt)
  4673. return false;
  4674. // Check type specific values
  4675. switch (vt)
  4676. {
  4677. case VT_EMPTY:
  4678. case VT_NULL:
  4679. return true;
  4680. case VT_BOOL:
  4681. return boolVal == varSrc.boolVal;
  4682. case VT_UI1:
  4683. return bVal == varSrc.bVal;
  4684. case VT_I2:
  4685. return iVal == varSrc.iVal;
  4686. case VT_I4:
  4687. return lVal == varSrc.lVal;
  4688. case VT_R4:
  4689. return fltVal == varSrc.fltVal;
  4690. case VT_R8:
  4691. return dblVal == varSrc.dblVal;
  4692. case VT_BSTR:
  4693. return (::SysStringByteLen(bstrVal) == ::SysStringByteLen(varSrc.bstrVal)) &&
  4694. (::memcmp(bstrVal, varSrc.bstrVal, ::SysStringByteLen(bstrVal)) == 0);
  4695. case VT_ERROR:
  4696. return scode == varSrc.scode;
  4697. case VT_DISPATCH:
  4698. return pdispVal == varSrc.pdispVal;
  4699. case VT_UNKNOWN:
  4700. return punkVal == varSrc.punkVal;
  4701. default:
  4702. ATLASSERT(false);
  4703. // fall through
  4704. }
  4705. return false;
  4706. }
  4707. bool operator!=(const VARIANT& varSrc) const {return !operator==(varSrc);}
  4708. bool operator<(const VARIANT& varSrc) const {return VarCmp((VARIANT*)this, (VARIANT*)&varSrc, LOCALE_USER_DEFAULT, 0)==VARCMP_LT;}
  4709. bool operator>(const VARIANT& varSrc) const {return VarCmp((VARIANT*)this, (VARIANT*)&varSrc, LOCALE_USER_DEFAULT, 0)==VARCMP_GT;}
  4710. bool operator!() const {
  4711. switch (vt)
  4712. {
  4713. case VT_EMPTY:
  4714. case VT_NULL:
  4715. return true;
  4716. case VT_BOOL:
  4717. return !boolVal;
  4718. case VT_UI1:
  4719. return !bVal;
  4720. case VT_I2:
  4721. return !iVal;
  4722. case VT_I4:
  4723. return !lVal;
  4724. case VT_R4:
  4725. return !fltVal;
  4726. case VT_R8:
  4727. return !dblVal;
  4728. case VT_BSTR:
  4729. return (bstrVal ? !::SysStringByteLen(bstrVal) : true);
  4730. case VT_ERROR:
  4731. return scode != S_OK;
  4732. case VT_DISPATCH:
  4733. return !pdispVal;
  4734. case VT_UNKNOWN:
  4735. return !punkVal;
  4736. default:
  4737. ATLASSERT(false);
  4738. // fall through
  4739. return true;
  4740. }
  4741. }
  4742. // Operations
  4743. public:
  4744. HRESULT Clear() { return ::VariantClear(this); }
  4745. HRESULT Copy(const VARIANT* pSrc) { return ::VariantCopy(this, const_cast<VARIANT*>(pSrc)); }
  4746. HRESULT CopyTo(VARIANT* pDest) { return ::VariantCopy(pDest, this); }
  4747. HRESULT Attach(VARIANT* pSrc)
  4748. {
  4749. // Clear out the variant
  4750. HRESULT hr = Clear();
  4751. if (!FAILED(hr))
  4752. {
  4753. // Copy the contents and give control to CComVariant
  4754. memcpy(this, pSrc, sizeof(VARIANT));
  4755. pSrc->vt = VT_EMPTY;
  4756. hr = S_OK;
  4757. }
  4758. return hr;
  4759. }
  4760. HRESULT Detach(VARIANT* pDest)
  4761. {
  4762. // Clear out the variant
  4763. HRESULT hr = ::VariantClear(pDest);
  4764. if (!FAILED(hr))
  4765. {
  4766. // Copy the contents and remove control from CComVariant
  4767. memcpy(pDest, this, sizeof(VARIANT));
  4768. vt = VT_EMPTY;
  4769. hr = S_OK;
  4770. }
  4771. return hr;
  4772. }
  4773. HRESULT ChangeType(VARTYPE vtNew, const VARIANT* pSrc = NULL)
  4774. {
  4775. VARIANT* pVar = const_cast<VARIANT*>(pSrc);
  4776. // Convert in place if pSrc is NULL
  4777. if (pVar == NULL)
  4778. pVar = this;
  4779. // Do nothing if doing in place convert and vts not different
  4780. return ::VariantChangeType(this, pVar, 0, vtNew);
  4781. }
  4782. HRESULT WriteToStream(IStream* pStream);
  4783. HRESULT ReadFromStream(IStream* pStream);
  4784. // Implementation
  4785. public:
  4786. HRESULT InternalClear()
  4787. {
  4788. HRESULT hr = Clear();
  4789. ATLASSERT(SUCCEEDED(hr));
  4790. if (FAILED(hr))
  4791. {
  4792. vt = VT_ERROR;
  4793. scode = hr;
  4794. }
  4795. return hr;
  4796. }
  4797. void InternalCopy(const VARIANT* pSrc)
  4798. {
  4799. HRESULT hr = Copy(pSrc);
  4800. if (FAILED(hr))
  4801. {
  4802. vt = VT_ERROR;
  4803. scode = hr;
  4804. }
  4805. }
  4806. // this allows direct use in stl containers
  4807. // without using the CAdapt template which causes extra addrefs/releases
  4808. // usage:
  4809. // std::vector<CComVariant, CComVariant::stl_allocator>
  4810. CComVariant * address(void) { return this; }
  4811. const CComVariant * const_address(void) const { return this; }
  4812. typedef stl_smart_ptr_allocator<CComVariant> stl_allocator;
  4813. };
  4814. inline HRESULT CComVariant::WriteToStream(IStream* pStream)
  4815. {
  4816. HRESULT hr = pStream->Write(&vt, sizeof(VARTYPE), NULL);
  4817. if (FAILED(hr))
  4818. return hr;
  4819. int cbWrite = 0;
  4820. switch (vt)
  4821. {
  4822. case VT_UNKNOWN:
  4823. case VT_DISPATCH:
  4824. {
  4825. CComPtr<IPersistStream> spStream;
  4826. if (punkVal != NULL)
  4827. {
  4828. hr = punkVal->QueryInterface(IID_IPersistStream, (void**)&spStream);
  4829. if (FAILED(hr))
  4830. return hr;
  4831. }
  4832. if (spStream != NULL)
  4833. return OleSaveToStream(spStream, pStream);
  4834. else
  4835. return WriteClassStm(pStream, CLSID_NULL);
  4836. }
  4837. case VT_UI1:
  4838. case VT_I1:
  4839. cbWrite = sizeof(BYTE);
  4840. break;
  4841. case VT_I2:
  4842. case VT_UI2:
  4843. case VT_BOOL:
  4844. cbWrite = sizeof(short);
  4845. break;
  4846. case VT_I4:
  4847. case VT_UI4:
  4848. case VT_R4:
  4849. case VT_INT:
  4850. case VT_UINT:
  4851. case VT_ERROR:
  4852. cbWrite = sizeof(long);
  4853. break;
  4854. case VT_R8:
  4855. case VT_CY:
  4856. case VT_DATE:
  4857. cbWrite = sizeof(double);
  4858. break;
  4859. default:
  4860. break;
  4861. }
  4862. if (cbWrite != 0)
  4863. return pStream->Write((void*) &bVal, cbWrite, NULL);
  4864. CComBSTR bstrWrite;
  4865. CComVariant varBSTR;
  4866. if (vt != VT_BSTR)
  4867. {
  4868. hr = VariantChangeType(&varBSTR, this, VARIANT_NOVALUEPROP, VT_BSTR);
  4869. if (FAILED(hr))
  4870. return hr;
  4871. bstrWrite = varBSTR.bstrVal;
  4872. }
  4873. else
  4874. bstrWrite = bstrVal;
  4875. return bstrWrite.WriteToStream(pStream);
  4876. }
  4877. inline HRESULT CComVariant::ReadFromStream(IStream* pStream)
  4878. {
  4879. ATLASSERT(pStream != NULL);
  4880. HRESULT hr;
  4881. hr = VariantClear(this);
  4882. if (FAILED(hr))
  4883. return hr;
  4884. VARTYPE vtRead;
  4885. hr = pStream->Read(&vtRead, sizeof(VARTYPE), NULL);
  4886. if (hr == S_FALSE)
  4887. hr = E_FAIL;
  4888. if (FAILED(hr))
  4889. return hr;
  4890. vt = vtRead;
  4891. int cbRead = 0;
  4892. switch (vtRead)
  4893. {
  4894. case VT_UNKNOWN:
  4895. case VT_DISPATCH:
  4896. {
  4897. punkVal = NULL;
  4898. hr = OleLoadFromStream(pStream,
  4899. (vtRead == VT_UNKNOWN) ? IID_IUnknown : IID_IDispatch,
  4900. (void**)&punkVal);
  4901. if (hr == REGDB_E_CLASSNOTREG)
  4902. hr = S_OK;
  4903. return S_OK;
  4904. }
  4905. case VT_UI1:
  4906. case VT_I1:
  4907. cbRead = sizeof(BYTE);
  4908. break;
  4909. case VT_I2:
  4910. case VT_UI2:
  4911. case VT_BOOL:
  4912. cbRead = sizeof(short);
  4913. break;
  4914. case VT_I4:
  4915. case VT_UI4:
  4916. case VT_R4:
  4917. case VT_INT:
  4918. case VT_UINT:
  4919. case VT_ERROR:
  4920. cbRead = sizeof(long);
  4921. break;
  4922. case VT_R8:
  4923. case VT_CY:
  4924. case VT_DATE:
  4925. cbRead = sizeof(double);
  4926. break;
  4927. default:
  4928. break;
  4929. }
  4930. if (cbRead != 0)
  4931. {
  4932. hr = pStream->Read((void*) &bVal, cbRead, NULL);
  4933. if (hr == S_FALSE)
  4934. hr = E_FAIL;
  4935. return hr;
  4936. }
  4937. CComBSTR bstrRead;
  4938. hr = bstrRead.ReadFromStream(pStream);
  4939. if (FAILED(hr))
  4940. return hr;
  4941. vt = VT_BSTR;
  4942. bstrVal = bstrRead.Detach();
  4943. if (vtRead != VT_BSTR)
  4944. hr = ChangeType(vtRead);
  4945. return hr;
  4946. }
  4947. /////////////////////////////////////////////////////////////////////////////
  4948. // CRegKey
  4949. class CRegKey
  4950. {
  4951. public:
  4952. CRegKey();
  4953. ~CRegKey();
  4954. // Attributes
  4955. public:
  4956. operator HKEY() const;
  4957. HKEY m_hKey;
  4958. // Operations
  4959. public:
  4960. LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName);
  4961. LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName);
  4962. LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount);
  4963. LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
  4964. LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
  4965. static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName,
  4966. LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
  4967. LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName,
  4968. LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE,
  4969. REGSAM samDesired = KEY_ALL_ACCESS,
  4970. LPSECURITY_ATTRIBUTES lpSecAttr = NULL,
  4971. LPDWORD lpdwDisposition = NULL);
  4972. LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName,
  4973. REGSAM samDesired = KEY_ALL_ACCESS, DWORD ulOptions = 0);
  4974. LONG Close();
  4975. HKEY Detach();
  4976. void Attach(HKEY hKey);
  4977. LONG DeleteSubKey(LPCTSTR lpszSubKey);
  4978. LONG RecurseDeleteKey(LPCTSTR lpszKey);
  4979. LONG DeleteValue(LPCTSTR lpszValue);
  4980. };
  4981. inline CRegKey::CRegKey()
  4982. {m_hKey = NULL;}
  4983. inline CRegKey::~CRegKey()
  4984. {Close();}
  4985. inline CRegKey::operator HKEY() const
  4986. {return m_hKey;}
  4987. inline HKEY CRegKey::Detach()
  4988. {
  4989. HKEY hKey = m_hKey;
  4990. m_hKey = NULL;
  4991. return hKey;
  4992. }
  4993. inline void CRegKey::Attach(HKEY hKey)
  4994. {
  4995. ATLASSERT(m_hKey == NULL);
  4996. m_hKey = hKey;
  4997. }
  4998. inline LONG CRegKey::DeleteSubKey(LPCTSTR lpszSubKey)
  4999. {
  5000. ATLASSERT(m_hKey != NULL);
  5001. return RegDeleteKey(m_hKey, lpszSubKey);
  5002. }
  5003. inline LONG CRegKey::DeleteValue(LPCTSTR lpszValue)
  5004. {
  5005. ATLASSERT(m_hKey != NULL);
  5006. return RegDeleteValue(m_hKey, (LPTSTR)lpszValue);
  5007. }
  5008. inline LONG CRegKey::Close()
  5009. {
  5010. LONG lRes = ERROR_SUCCESS;
  5011. if (m_hKey != NULL)
  5012. {
  5013. lRes = RegCloseKey(m_hKey);
  5014. m_hKey = NULL;
  5015. }
  5016. return lRes;
  5017. }
  5018. inline LONG CRegKey::Create(HKEY hKeyParent, LPCTSTR lpszKeyName,
  5019. LPTSTR lpszClass, DWORD dwOptions, REGSAM samDesired,
  5020. LPSECURITY_ATTRIBUTES lpSecAttr, LPDWORD lpdwDisposition)
  5021. {
  5022. ATLASSERT(hKeyParent != NULL);
  5023. DWORD dw;
  5024. HKEY hKey = NULL;
  5025. LONG lRes = RegCreateKeyEx(hKeyParent, lpszKeyName, 0,
  5026. lpszClass, dwOptions, samDesired, lpSecAttr, &hKey, &dw);
  5027. if (lpdwDisposition != NULL)
  5028. *lpdwDisposition = dw;
  5029. if (lRes == ERROR_SUCCESS)
  5030. {
  5031. lRes = Close();
  5032. m_hKey = hKey;
  5033. }
  5034. return lRes;
  5035. }
  5036. inline LONG CRegKey::Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired, DWORD ulOptions)
  5037. {
  5038. ATLASSERT(hKeyParent != NULL);
  5039. HKEY hKey = NULL;
  5040. LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyName, ulOptions, samDesired, &hKey);
  5041. if (lRes == ERROR_SUCCESS)
  5042. {
  5043. lRes = Close();
  5044. ATLASSERT(lRes == ERROR_SUCCESS);
  5045. m_hKey = hKey;
  5046. }
  5047. return lRes;
  5048. }
  5049. inline LONG CRegKey::QueryValue(DWORD& dwValue, LPCTSTR lpszValueName)
  5050. {
  5051. DWORD dwType = NULL;
  5052. DWORD dwCount = sizeof(DWORD);
  5053. LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
  5054. (LPBYTE)&dwValue, &dwCount);
  5055. ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_DWORD));
  5056. ATLASSERT((lRes!=ERROR_SUCCESS) || (dwCount == sizeof(DWORD)));
  5057. return lRes;
  5058. }
  5059. inline LONG CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount)
  5060. {
  5061. ATLASSERT(pdwCount != NULL);
  5062. DWORD dwType = NULL;
  5063. LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
  5064. (LPBYTE)szValue, pdwCount);
  5065. ATLASSERT((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) ||
  5066. (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ));
  5067. return lRes;
  5068. }
  5069. inline LONG WINAPI CRegKey::SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName)
  5070. {
  5071. ATLASSERT(lpszValue != NULL);
  5072. CRegKey key;
  5073. LONG lRes = key.Create(hKeyParent, lpszKeyName);
  5074. if (lRes == ERROR_SUCCESS)
  5075. lRes = key.SetValue(lpszValue, lpszValueName);
  5076. return lRes;
  5077. }
  5078. inline LONG CRegKey::SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName)
  5079. {
  5080. ATLASSERT(lpszValue != NULL);
  5081. CRegKey key;
  5082. LONG lRes = key.Create(m_hKey, lpszKeyName);
  5083. if (lRes == ERROR_SUCCESS)
  5084. lRes = key.SetValue(lpszValue, lpszValueName);
  5085. return lRes;
  5086. }
  5087. inline LONG CRegKey::SetValue(DWORD dwValue, LPCTSTR lpszValueName)
  5088. {
  5089. ATLASSERT(m_hKey != NULL);
  5090. return RegSetValueEx(m_hKey, lpszValueName, NULL, REG_DWORD,
  5091. (BYTE * const)&dwValue, sizeof(DWORD));
  5092. }
  5093. inline LONG CRegKey::SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName)
  5094. {
  5095. ATLASSERT(lpszValue != NULL);
  5096. ATLASSERT(m_hKey != NULL);
  5097. return RegSetValueEx(m_hKey, lpszValueName, NULL, REG_SZ,
  5098. (BYTE * const)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
  5099. }
  5100. inline LONG CRegKey::RecurseDeleteKey(LPCTSTR lpszKey)
  5101. {
  5102. CRegKey key;
  5103. LONG lRes = key.Open(m_hKey, lpszKey, KEY_READ | KEY_WRITE);
  5104. if (lRes != ERROR_SUCCESS)
  5105. return lRes;
  5106. FILETIME time;
  5107. DWORD dwSize = 256;
  5108. TCHAR szBuffer[256];
  5109. while (RegEnumKeyEx(key.m_hKey, 0, szBuffer, &dwSize, NULL, NULL, NULL,
  5110. &time)==ERROR_SUCCESS)
  5111. {
  5112. lRes = key.RecurseDeleteKey(szBuffer);
  5113. if (lRes != ERROR_SUCCESS)
  5114. return lRes;
  5115. dwSize = 256;
  5116. }
  5117. key.Close();
  5118. return DeleteSubKey(lpszKey);
  5119. }
  5120. inline HRESULT CComModule::RegisterProgID(LPCTSTR lpszCLSID, LPCTSTR lpszProgID, LPCTSTR lpszUserDesc)
  5121. {
  5122. CRegKey keyProgID;
  5123. LONG lRes = keyProgID.Create(HKEY_CLASSES_ROOT, lpszProgID, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE);
  5124. if (lRes == ERROR_SUCCESS)
  5125. {
  5126. keyProgID.SetValue(lpszUserDesc);
  5127. keyProgID.SetKeyValue(_T("CLSID"), lpszCLSID);
  5128. return S_OK;
  5129. }
  5130. return HRESULT_FROM_WIN32(lRes);
  5131. }
  5132. #ifdef _ATL_STATIC_REGISTRY
  5133. #include <statreg.h>
  5134. // Statically linking to Registry Ponent
  5135. inline HRESULT WINAPI CComModule::UpdateRegistryFromResourceS(UINT nResID, BOOL bRegister,
  5136. struct _ATL_REGMAP_ENTRY* pMapEntries)
  5137. {
  5138. USES_CONVERSION;
  5139. ATL::CRegObject ro;
  5140. TCHAR szModule[_MAX_PATH];
  5141. GetModuleFileName(_pModule->GetModuleInstance(), szModule, _MAX_PATH);
  5142. LPOLESTR pszModule;
  5143. if ((m_hInst == NULL) || (m_hInst == GetModuleHandle(NULL))) // register as EXE
  5144. {
  5145. // Convert to short path to work around bug in NT4's CreateProcess
  5146. TCHAR szModuleShort[_MAX_PATH];
  5147. int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH);
  5148. if (cbShortName == _MAX_PATH)
  5149. return E_OUTOFMEMORY;
  5150. pszModule = (cbShortName == 0 || cbShortName == ERROR_INVALID_PARAMETER) ? T2OLE(szModule) : T2OLE(szModuleShort);
  5151. }
  5152. else
  5153. pszModule = T2OLE(szModule);
  5154. int nLen = ocslen(pszModule);
  5155. LPOLESTR pszModuleQuote = (LPOLESTR)alloca((nLen*2+1)*sizeof(OLECHAR));
  5156. ReplaceSingleQuote(pszModuleQuote, pszModule);
  5157. ro.AddReplacement(OLESTR("Module"), pszModuleQuote);
  5158. if (NULL != pMapEntries)
  5159. {
  5160. while (NULL != pMapEntries->szKey)
  5161. {
  5162. ATLASSERT(NULL != pMapEntries->szData);
  5163. ro.AddReplacement(pMapEntries->szKey, pMapEntries->szData);
  5164. pMapEntries++;
  5165. }
  5166. }
  5167. LPCOLESTR szType = OLESTR("REGISTRY");
  5168. return (bRegister) ? ro.ResourceRegister(pszModule, nResID, szType) :
  5169. ro.ResourceUnregister(pszModule, nResID, szType);
  5170. }
  5171. inline HRESULT WINAPI CComModule::UpdateRegistryFromResourceS(LPCTSTR lpszRes, BOOL bRegister,
  5172. struct _ATL_REGMAP_ENTRY* pMapEntries)
  5173. {
  5174. USES_CONVERSION;
  5175. ATL::CRegObject ro;
  5176. TCHAR szModule[_MAX_PATH];
  5177. GetModuleFileName(_pModule->GetModuleInstance(), szModule, _MAX_PATH);
  5178. LPOLESTR pszModule;
  5179. if ((m_hInst == NULL) || (m_hInst == GetModuleHandle(NULL))) // register as EXE
  5180. {
  5181. // Convert to short path to work around bug in NT4's CreateProcess
  5182. TCHAR szModuleShort[_MAX_PATH];
  5183. int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH);
  5184. if (cbShortName == _MAX_PATH)
  5185. return E_OUTOFMEMORY;
  5186. pszModule = (cbShortName == 0 || cbShortName == ERROR_INVALID_PARAMETER) ? T2OLE(szModule) : T2OLE(szModuleShort);
  5187. }
  5188. else
  5189. pszModule = T2OLE(szModule);
  5190. int nLen = ocslen(pszModule);
  5191. LPOLESTR pszModuleQuote = (LPOLESTR)alloca((nLen*2+1)*sizeof(OLECHAR));
  5192. ReplaceSingleQuote(pszModuleQuote, pszModule);
  5193. ro.AddReplacement(OLESTR("Module"), pszModuleQuote);
  5194. if (NULL != pMapEntries)
  5195. {
  5196. while (NULL != pMapEntries->szKey)
  5197. {
  5198. ATLASSERT(NULL != pMapEntries->szData);
  5199. ro.AddReplacement(pMapEntries->szKey, pMapEntries->szData);
  5200. pMapEntries++;
  5201. }
  5202. }
  5203. LPCOLESTR szType = OLESTR("REGISTRY");
  5204. LPCOLESTR pszRes = T2COLE(lpszRes);
  5205. return (bRegister) ? ro.ResourceRegisterSz(pszModule, pszRes, szType) :
  5206. ro.ResourceUnregisterSz(pszModule, pszRes, szType);
  5207. }
  5208. #endif //_ATL_STATIC_REGISTRY
  5209. inline HRESULT WINAPI CComModule::UpdateRegistryClass(const CLSID& clsid, LPCTSTR lpszProgID,
  5210. LPCTSTR lpszVerIndProgID, UINT nDescID, DWORD dwFlags, BOOL bRegister)
  5211. {
  5212. if (bRegister)
  5213. {
  5214. return RegisterClassHelper(clsid, lpszProgID, lpszVerIndProgID, nDescID,
  5215. dwFlags);
  5216. }
  5217. else
  5218. return UnregisterClassHelper(clsid, lpszProgID, lpszVerIndProgID);
  5219. }
  5220. inline HRESULT WINAPI CComModule::RegisterClassHelper(const CLSID& clsid, LPCTSTR lpszProgID,
  5221. LPCTSTR lpszVerIndProgID, UINT nDescID, DWORD dwFlags)
  5222. {
  5223. static const TCHAR szProgID[] = _T("ProgID");
  5224. static const TCHAR szVIProgID[] = _T("VersionIndependentProgID");
  5225. static const TCHAR szLS32[] = _T("LocalServer32");
  5226. static const TCHAR szIPS32[] = _T("InprocServer32");
  5227. static const TCHAR szThreadingModel[] = _T("ThreadingModel");
  5228. static const TCHAR szAUTPRX32[] = _T("AUTPRX32.DLL");
  5229. static const TCHAR szApartment[] = _T("Apartment");
  5230. static const TCHAR szBoth[] = _T("both");
  5231. USES_CONVERSION;
  5232. HRESULT hRes = S_OK;
  5233. TCHAR szDesc[256];
  5234. LoadString(m_hInst, nDescID, szDesc, 256);
  5235. TCHAR szModule[_MAX_PATH];
  5236. GetModuleFileName(m_hInst, szModule, _MAX_PATH);
  5237. LPOLESTR lpOleStr;
  5238. StringFromCLSID(clsid, &lpOleStr);
  5239. LPTSTR lpsz = OLE2T(lpOleStr);
  5240. hRes = RegisterProgID(lpsz, lpszProgID, szDesc);
  5241. if (hRes == S_OK)
  5242. hRes = RegisterProgID(lpsz, lpszVerIndProgID, szDesc);
  5243. LONG lRes = ERROR_SUCCESS;
  5244. if (hRes == S_OK)
  5245. {
  5246. CRegKey key;
  5247. lRes = key.Open(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_READ | KEY_WRITE);
  5248. if (lRes == ERROR_SUCCESS)
  5249. {
  5250. lRes = key.Create(key, lpsz, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE);
  5251. if (lRes == ERROR_SUCCESS)
  5252. {
  5253. key.SetValue(szDesc);
  5254. key.SetKeyValue(szProgID, lpszProgID);
  5255. key.SetKeyValue(szVIProgID, lpszVerIndProgID);
  5256. if ((m_hInst == NULL) || (m_hInst == GetModuleHandle(NULL))) // register as EXE
  5257. {
  5258. // Convert to short path to work around bug in NT4's CreateProcess
  5259. TCHAR szModuleShort[_MAX_PATH];
  5260. int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH);
  5261. TCHAR* pszModule;
  5262. if (cbShortName == _MAX_PATH)
  5263. return E_OUTOFMEMORY;
  5264. pszModule = (cbShortName == 0 || cbShortName == ERROR_INVALID_PARAMETER) ? szModule : szModuleShort;
  5265. key.SetKeyValue(szLS32, pszModule);
  5266. }
  5267. else
  5268. {
  5269. key.SetKeyValue(szIPS32, (dwFlags & AUTPRXFLAG) ? szAUTPRX32 : szModule);
  5270. LPCTSTR lpszModel = (dwFlags & THREADFLAGS_BOTH) ? szBoth :
  5271. (dwFlags & THREADFLAGS_APARTMENT) ? szApartment : NULL;
  5272. if (lpszModel != NULL)
  5273. key.SetKeyValue(szIPS32, lpszModel, szThreadingModel);
  5274. }
  5275. }
  5276. }
  5277. }
  5278. CoTaskMemFree(lpOleStr);
  5279. if (lRes != ERROR_SUCCESS)
  5280. hRes = HRESULT_FROM_WIN32(lRes);
  5281. return hRes;
  5282. }
  5283. inline HRESULT WINAPI CComModule::UnregisterClassHelper(const CLSID& clsid, LPCTSTR lpszProgID,
  5284. LPCTSTR lpszVerIndProgID)
  5285. {
  5286. USES_CONVERSION;
  5287. CRegKey key;
  5288. key.Attach(HKEY_CLASSES_ROOT);
  5289. if (lpszProgID != NULL && lstrcmpi(lpszProgID, _T("")))
  5290. key.RecurseDeleteKey(lpszProgID);
  5291. if (lpszVerIndProgID != NULL && lstrcmpi(lpszVerIndProgID, _T("")))
  5292. key.RecurseDeleteKey(lpszVerIndProgID);
  5293. LPOLESTR lpOleStr;
  5294. StringFromCLSID(clsid, &lpOleStr);
  5295. LPTSTR lpsz = OLE2T(lpOleStr);
  5296. if (key.Open(key, _T("CLSID"), KEY_READ | KEY_WRITE) == ERROR_SUCCESS)
  5297. key.RecurseDeleteKey(lpsz);
  5298. CoTaskMemFree(lpOleStr);
  5299. return S_OK;
  5300. }
  5301. /////////////////////////////////////////////////////////////////////////////
  5302. // Large Block Allocation Helper - CVBufHelper & CVirtualBuffer
  5303. template <class T>
  5304. class CVBufHelper
  5305. {
  5306. public:
  5307. virtual T* operator()(T* pCurrent) {return pCurrent;}
  5308. };
  5309. template <class T>
  5310. class CVirtualBuffer
  5311. {
  5312. protected:
  5313. CVirtualBuffer() {}
  5314. T* m_pBase;
  5315. T* m_pCurrent;
  5316. T* m_pTop;
  5317. int m_nMaxElements;
  5318. public:
  5319. CVirtualBuffer(int nMaxElements)
  5320. {
  5321. m_nMaxElements = nMaxElements;
  5322. m_pBase = (T*) VirtualAlloc(NULL, sizeof(T) * nMaxElements,
  5323. MEM_RESERVE, PAGE_READWRITE);
  5324. m_pTop = m_pCurrent = m_pBase;
  5325. // Commit first page - chances are this is all that will be used
  5326. VirtualAlloc(m_pBase, sizeof(T), MEM_COMMIT, PAGE_READWRITE);
  5327. }
  5328. ~CVirtualBuffer()
  5329. {
  5330. VirtualFree(m_pBase, 0, MEM_RELEASE);
  5331. }
  5332. int Except(LPEXCEPTION_POINTERS lpEP)
  5333. {
  5334. EXCEPTION_RECORD* pExcept = lpEP->ExceptionRecord;
  5335. if (pExcept->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
  5336. return EXCEPTION_CONTINUE_SEARCH;
  5337. BYTE* pAddress = (LPBYTE) pExcept->ExceptionInformation[1];
  5338. VirtualAlloc(pAddress, ((BYTE*)m_pTop - (BYTE*)m_pBase), MEM_COMMIT, PAGE_READWRITE);
  5339. return EXCEPTION_CONTINUE_EXECUTION;
  5340. }
  5341. void Seek(int nElement)
  5342. {
  5343. m_pCurrent = &m_pBase[nElement];
  5344. }
  5345. void SetAt(int nElement, const T& Element)
  5346. {
  5347. __try
  5348. {
  5349. T* p = &m_pBase[nElement]
  5350. *p = Element;
  5351. m_pTop = p > m_pTop ? p : m_pTop;
  5352. }
  5353. __except(Except(GetExceptionInformation()))
  5354. {
  5355. }
  5356. }
  5357. template <class Q>
  5358. void WriteBulk(Q& helper)
  5359. {
  5360. __try
  5361. {
  5362. m_pCurrent = helper(m_pBase);
  5363. m_pTop = m_pCurrent > m_pTop ? m_pCurrent : m_pTop;
  5364. }
  5365. __except(Except(GetExceptionInformation()))
  5366. {
  5367. }
  5368. }
  5369. void Write(const T& Element)
  5370. {
  5371. __try
  5372. {
  5373. *m_pCurrent = Element;
  5374. m_pCurrent++;
  5375. m_pTop = m_pCurrent > m_pTop ? m_pCurrent : m_pTop;
  5376. }
  5377. __except(Except(GetExceptionInformation()))
  5378. {
  5379. }
  5380. }
  5381. T& Read()
  5382. {
  5383. return *m_pCurrent;
  5384. }
  5385. operator BSTR()
  5386. {
  5387. BSTR bstrTemp;
  5388. __try
  5389. {
  5390. bstrTemp = SysAllocStringByteLen((char*) m_pBase,
  5391. (UINT) ((BYTE*)m_pTop - (BYTE*)m_pBase));
  5392. }
  5393. __except(Except(GetExceptionInformation()))
  5394. {
  5395. }
  5396. return bstrTemp;
  5397. }
  5398. const T& operator[](int nElement) const
  5399. {
  5400. return m_pBase[nElement];
  5401. }
  5402. operator T*()
  5403. {
  5404. return m_pBase;
  5405. }
  5406. };
  5407. typedef CVirtualBuffer<BYTE> CVirtualBytes;
  5408. inline HRESULT WINAPI AtlDumpIID(REFIID iid, LPCTSTR pszClassName, HRESULT hr)
  5409. {
  5410. if (atlTraceQI & ATL_TRACE_CATEGORY)
  5411. {
  5412. USES_CONVERSION;
  5413. CRegKey key;
  5414. TCHAR szName[100];
  5415. DWORD dwType,dw = sizeof(szName);
  5416. LPOLESTR pszGUID = NULL;
  5417. StringFromCLSID(iid, &pszGUID);
  5418. OutputDebugString(pszClassName);
  5419. OutputDebugString(_T(" - "));
  5420. // Attempt to find it in the interfaces section
  5421. key.Open(HKEY_CLASSES_ROOT, _T("Interface"), KEY_READ);
  5422. if (key.Open(key, OLE2T(pszGUID), KEY_READ) == S_OK)
  5423. {
  5424. *szName = 0;
  5425. RegQueryValueEx(key.m_hKey, (LPTSTR)NULL, NULL, &dwType, (LPBYTE)szName, &dw);
  5426. OutputDebugString(szName);
  5427. goto cleanup;
  5428. }
  5429. // Attempt to find it in the clsid section
  5430. key.Open(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_READ);
  5431. if (key.Open(key, OLE2T(pszGUID), KEY_READ) == S_OK)
  5432. {
  5433. *szName = 0;
  5434. RegQueryValueEx(key.m_hKey, (LPTSTR)NULL, NULL, &dwType, (LPBYTE)szName, &dw);
  5435. OutputDebugString(_T("(CLSID\?\?\?) "));
  5436. OutputDebugString(szName);
  5437. goto cleanup;
  5438. }
  5439. OutputDebugString(OLE2T(pszGUID));
  5440. cleanup:
  5441. if (hr != S_OK)
  5442. OutputDebugString(_T(" - failed"));
  5443. OutputDebugString(_T("\n"));
  5444. CoTaskMemFree(pszGUID);
  5445. }
  5446. return hr;
  5447. }
  5448. #pragma pack(pop)
  5449. // WM_FORWARDMSG - used to forward a message to another window for processing
  5450. // WPARAM - DWORD dwUserData - defined by user
  5451. // LPARAM - LPMSG pMsg - a pointer to the MSG structure
  5452. // return value - 0 if the message was not processed, nonzero if it was
  5453. #define WM_FORWARDMSG 0x037F
  5454. }; //namespace ATL
  5455. using namespace ATL;
  5456. //only pull in definition if static linking
  5457. #ifndef _ATL_DLL_IMPL
  5458. #ifndef _ATL_DLL
  5459. #define _ATLBASE_IMPL
  5460. #endif
  5461. #endif
  5462. #ifdef _ATL_REDEF_NEW
  5463. #pragma pop_macro("new")
  5464. #undef _ATL_REDEF_NEW
  5465. #endif
  5466. #endif // __ATLBASE_H__
  5467. //All exports go here
  5468. #ifdef _ATLBASE_IMPL
  5469. #ifndef _ATL_DLL_IMPL
  5470. namespace ATL
  5471. {
  5472. #endif
  5473. /////////////////////////////////////////////////////////////////////////////
  5474. // statics
  5475. static UINT WINAPI AtlGetDirLen(LPCOLESTR lpszPathName)
  5476. {
  5477. ATLASSERT(lpszPathName != NULL);
  5478. // always capture the complete file name including extension (if present)
  5479. LPCOLESTR lpszTemp = lpszPathName;
  5480. for (LPCOLESTR lpsz = lpszPathName; *lpsz != NULL; )
  5481. {
  5482. LPCOLESTR lp = CharNextO(lpsz);
  5483. // remember last directory/drive separator
  5484. if (*lpsz == OLESTR('\\') || *lpsz == OLESTR('/') || *lpsz == OLESTR(':'))
  5485. lpszTemp = lp;
  5486. lpsz = lp;
  5487. }
  5488. return UINT(lpszTemp-lpszPathName);
  5489. }
  5490. /////////////////////////////////////////////////////////////////////////////
  5491. // QI support
  5492. ATLINLINE ATLAPI AtlInternalQueryInterface(void* pThis,
  5493. const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, void** ppvObject)
  5494. {
  5495. ATLASSERT(pThis != NULL);
  5496. // First entry in the com map should be a simple map entry
  5497. ATLASSERT(pEntries->pFunc == _ATL_SIMPLEMAPENTRY);
  5498. if (ppvObject == NULL)
  5499. return E_POINTER;
  5500. *ppvObject = NULL;
  5501. if (InlineIsEqualUnknown(iid)) // use first interface
  5502. {
  5503. IUnknown* pUnk = (IUnknown*)((DWORD_PTR)pThis+pEntries->dw);
  5504. pUnk->AddRef();
  5505. *ppvObject = pUnk;
  5506. return S_OK;
  5507. }
  5508. while (pEntries->pFunc != NULL)
  5509. {
  5510. BOOL bBlind = (pEntries->piid == NULL);
  5511. if (bBlind || InlineIsEqualGUID(*(pEntries->piid), iid))
  5512. {
  5513. if (pEntries->pFunc == _ATL_SIMPLEMAPENTRY) //offset
  5514. {
  5515. ATLASSERT(!bBlind);
  5516. IUnknown* pUnk = (IUnknown*)((DWORD_PTR)pThis+pEntries->dw);
  5517. pUnk->AddRef();
  5518. *ppvObject = pUnk;
  5519. return S_OK;
  5520. }
  5521. else //actual function call
  5522. {
  5523. HRESULT hRes = pEntries->pFunc(pThis,
  5524. iid, ppvObject, pEntries->dw);
  5525. if (hRes == S_OK || (!bBlind && FAILED(hRes)))
  5526. return hRes;
  5527. }
  5528. }
  5529. pEntries++;
  5530. }
  5531. return E_NOINTERFACE;
  5532. }
  5533. /////////////////////////////////////////////////////////////////////////////
  5534. // Smart Pointer helpers
  5535. ATLINLINE ATLAPI_(IUnknown*) AtlComPtrAssign(IUnknown** pp, IUnknown* lp)
  5536. {
  5537. if (lp != NULL)
  5538. lp->AddRef();
  5539. if (*pp)
  5540. (*pp)->Release();
  5541. *pp = lp;
  5542. return lp;
  5543. }
  5544. ATLINLINE ATLAPI_(IUnknown*) AtlComQIPtrAssign(IUnknown** pp, IUnknown* lp, REFIID riid)
  5545. {
  5546. IUnknown* pTemp = *pp;
  5547. *pp = NULL;
  5548. if (lp != NULL)
  5549. lp->QueryInterface(riid, (void**)pp);
  5550. if (pTemp)
  5551. pTemp->Release();
  5552. return *pp;
  5553. }
  5554. /////////////////////////////////////////////////////////////////////////////
  5555. // Inproc Marshaling helpers
  5556. //This API should be called from the same thread that called
  5557. //AtlMarshalPtrInProc
  5558. ATLINLINE ATLAPI AtlFreeMarshalStream(IStream* pStream)
  5559. {
  5560. if (pStream != NULL)
  5561. {
  5562. LARGE_INTEGER l;
  5563. l.QuadPart = 0;
  5564. pStream->Seek(l, STREAM_SEEK_SET, NULL);
  5565. CoReleaseMarshalData(pStream);
  5566. pStream->Release();
  5567. }
  5568. return S_OK;
  5569. }
  5570. ATLINLINE ATLAPI AtlMarshalPtrInProc(IUnknown* pUnk, const IID& iid, IStream** ppStream)
  5571. {
  5572. HRESULT hRes = CreateStreamOnHGlobal(NULL, TRUE, ppStream);
  5573. if (SUCCEEDED(hRes))
  5574. {
  5575. hRes = CoMarshalInterface(*ppStream, iid,
  5576. pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_TABLESTRONG);
  5577. if (FAILED(hRes))
  5578. {
  5579. (*ppStream)->Release();
  5580. *ppStream = NULL;
  5581. }
  5582. }
  5583. return hRes;
  5584. }
  5585. ATLINLINE ATLAPI AtlUnmarshalPtr(IStream* pStream, const IID& iid, IUnknown** ppUnk)
  5586. {
  5587. *ppUnk = NULL;
  5588. HRESULT hRes = E_INVALIDARG;
  5589. if (pStream != NULL)
  5590. {
  5591. LARGE_INTEGER l;
  5592. l.QuadPart = 0;
  5593. pStream->Seek(l, STREAM_SEEK_SET, NULL);
  5594. hRes = CoUnmarshalInterface(pStream, iid, (void**)ppUnk);
  5595. }
  5596. return hRes;
  5597. }
  5598. ATLINLINE ATLAPI_(BOOL) AtlWaitWithMessageLoop(HANDLE hEvent)
  5599. {
  5600. DWORD dwRet;
  5601. MSG msg;
  5602. while(1)
  5603. {
  5604. dwRet = MsgWaitForMultipleObjects(1, &hEvent, FALSE, INFINITE, QS_ALLINPUT);
  5605. if (dwRet == WAIT_OBJECT_0)
  5606. return TRUE; // The event was signaled
  5607. if (dwRet != WAIT_OBJECT_0 + 1)
  5608. break; // Something else happened
  5609. // There is one or more window message available. Dispatch them
  5610. while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
  5611. {
  5612. TranslateMessage(&msg);
  5613. DispatchMessage(&msg);
  5614. if (WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0)
  5615. return TRUE; // Event is now signaled.
  5616. }
  5617. }
  5618. return FALSE;
  5619. }
  5620. /////////////////////////////////////////////////////////////////////////////
  5621. // Connection Point Helpers
  5622. ATLINLINE ATLAPI AtlAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw)
  5623. {
  5624. CComPtr<IConnectionPointContainer> pCPC;
  5625. CComPtr<IConnectionPoint> pCP;
  5626. HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
  5627. if (SUCCEEDED(hRes))
  5628. hRes = pCPC->FindConnectionPoint(iid, &pCP);
  5629. if (SUCCEEDED(hRes))
  5630. hRes = pCP->Advise(pUnk, pdw);
  5631. return hRes;
  5632. }
  5633. ATLINLINE ATLAPI AtlUnadvise(IUnknown* pUnkCP, const IID& iid, DWORD dw)
  5634. {
  5635. CComPtr<IConnectionPointContainer> pCPC;
  5636. CComPtr<IConnectionPoint> pCP;
  5637. HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
  5638. if (SUCCEEDED(hRes))
  5639. hRes = pCPC->FindConnectionPoint(iid, &pCP);
  5640. if (SUCCEEDED(hRes))
  5641. hRes = pCP->Unadvise(dw);
  5642. return hRes;
  5643. }
  5644. /////////////////////////////////////////////////////////////////////////////
  5645. // IDispatch Error handling
  5646. ATLINLINE ATLAPI AtlSetErrorInfo(const CLSID& clsid, LPCOLESTR lpszDesc, DWORD dwHelpID,
  5647. LPCOLESTR lpszHelpFile, const IID& iid, HRESULT hRes, HINSTANCE hInst)
  5648. {
  5649. USES_CONVERSION;
  5650. TCHAR szDesc[1024];
  5651. szDesc[0] = NULL;
  5652. // For a valid HRESULT the id should be in the range [0x0200, 0xffff]
  5653. if (IS_INTRESOURCE(lpszDesc)) //id
  5654. {
  5655. UINT nID = LOWORD((DWORD_PTR)lpszDesc);
  5656. ATLASSERT((nID >= 0x0200 && nID <= 0xffff) || hRes != 0);
  5657. if (LoadString(hInst, nID, szDesc, 1024) == 0)
  5658. {
  5659. ATLASSERT(FALSE);
  5660. lstrcpy(szDesc, _T("Unknown Error"));
  5661. }
  5662. lpszDesc = T2OLE(szDesc);
  5663. if (hRes == 0)
  5664. hRes = MAKE_HRESULT(3, FACILITY_ITF, nID);
  5665. }
  5666. CComPtr<ICreateErrorInfo> pICEI;
  5667. if (SUCCEEDED(CreateErrorInfo(&pICEI)))
  5668. {
  5669. CComPtr<IErrorInfo> pErrorInfo;
  5670. pICEI->SetGUID(iid);
  5671. LPOLESTR lpsz;
  5672. ProgIDFromCLSID(clsid, &lpsz);
  5673. if (lpsz != NULL)
  5674. pICEI->SetSource(lpsz);
  5675. if (dwHelpID != 0 && lpszHelpFile != NULL)
  5676. {
  5677. pICEI->SetHelpContext(dwHelpID);
  5678. pICEI->SetHelpFile(const_cast<LPOLESTR>(lpszHelpFile));
  5679. }
  5680. CoTaskMemFree(lpsz);
  5681. pICEI->SetDescription((LPOLESTR)lpszDesc);
  5682. if (SUCCEEDED(pICEI->QueryInterface(IID_IErrorInfo, (void**)&pErrorInfo)))
  5683. SetErrorInfo(0, pErrorInfo);
  5684. }
  5685. return (hRes == 0) ? DISP_E_EXCEPTION : hRes;
  5686. }
  5687. ATLINLINE ATLAPI AtlSetErrorInfo(const CLSID& clsid, HRESULT hr, const IID& iid, HRESULT hRes, HINSTANCE hInst, va_list *Arguments)
  5688. {
  5689. // Mostly the same as the default AtlSetErrorInfo but this one loads strings from the module and allows arguments
  5690. // Arguments argument also allows for no ambiguity
  5691. USES_CONVERSION;
  5692. TCHAR szDesc[1024];
  5693. szDesc[0] = NULL;
  5694. // Attempt to load string from system
  5695. if (LoadString(hInst, hr, szDesc, 1024) == 0){
  5696. // If it is a no go try to load from the module
  5697. if(FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, hInst, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) szDesc, 1023, Arguments) == 0){
  5698. ATLASSERT(FALSE);
  5699. lstrcpy(szDesc, _T("Unknown Error"));
  5700. }
  5701. }
  5702. LPCOLESTR lpszDesc = T2OLE(szDesc);
  5703. if (hRes == 0){
  5704. hRes = hr;
  5705. }
  5706. CComPtr<ICreateErrorInfo> pICEI;
  5707. if (SUCCEEDED(CreateErrorInfo(&pICEI)))
  5708. {
  5709. CComPtr<IErrorInfo> pErrorInfo;
  5710. pICEI->SetGUID(iid);
  5711. LPOLESTR lpsz;
  5712. ProgIDFromCLSID(clsid, &lpsz);
  5713. if (lpsz != NULL)
  5714. pICEI->SetSource(lpsz);
  5715. CoTaskMemFree(lpsz);
  5716. pICEI->SetDescription((LPOLESTR)lpszDesc);
  5717. if (SUCCEEDED(pICEI->QueryInterface(IID_IErrorInfo, (void**)&pErrorInfo)))
  5718. SetErrorInfo(0, pErrorInfo);
  5719. }
  5720. return (hRes == 0) ? DISP_E_EXCEPTION : hRes;
  5721. }
  5722. /////////////////////////////////////////////////////////////////////////////
  5723. // Module
  5724. struct _ATL_MODULE20
  5725. {
  5726. // Attributes
  5727. public:
  5728. UINT cbSize;
  5729. HINSTANCE m_hInst;
  5730. HINSTANCE m_hInstResource;
  5731. HINSTANCE m_hInstTypeLib;
  5732. _ATL_OBJMAP_ENTRY* m_pObjMap;
  5733. LONG m_nLockCnt;
  5734. HANDLE m_hHeap;
  5735. CRITICAL_SECTION m_csTypeInfoHolder;
  5736. CRITICAL_SECTION m_csWindowCreate;
  5737. CRITICAL_SECTION m_csObjMap;
  5738. };
  5739. typedef _ATL_MODULE _ATL_MODULE30;
  5740. struct _ATL_OBJMAP_ENTRY20
  5741. {
  5742. const CLSID* pclsid;
  5743. HRESULT (WINAPI *pfnUpdateRegistry)(BOOL bRegister);
  5744. _ATL_CREATORFUNC* pfnGetClassObject;
  5745. _ATL_CREATORFUNC* pfnCreateInstance;
  5746. IUnknown* pCF;
  5747. DWORD dwRegister;
  5748. _ATL_DESCRIPTIONFUNC* pfnGetObjectDescription;
  5749. };
  5750. typedef _ATL_OBJMAP_ENTRY _ATL_OBJMAP_ENTRY30;
  5751. inline _ATL_OBJMAP_ENTRY* _NextObjectMapEntry(_ATL_MODULE* pM, _ATL_OBJMAP_ENTRY* pEntry)
  5752. {
  5753. if (pM->cbSize == sizeof(_ATL_MODULE20))
  5754. return (_ATL_OBJMAP_ENTRY*)(((BYTE*)pEntry) + sizeof(_ATL_OBJMAP_ENTRY20));
  5755. return pEntry+1;
  5756. }
  5757. //Although these functions are big, they are only used once in a module
  5758. //so we should make them inline.
  5759. ATLINLINE ATLAPI AtlModuleInit(_ATL_MODULE* pM, _ATL_OBJMAP_ENTRY* p, HINSTANCE h)
  5760. {
  5761. ATLASSERT(pM != NULL);
  5762. if (pM == NULL)
  5763. return E_INVALIDARG;
  5764. #ifdef _ATL_DLL_IMPL
  5765. if ((pM->cbSize != _nAtlModuleVer21Size) && (pM->cbSize != _nAtlModuleVer30Size) &&
  5766. (pM->cbSize != sizeof(_ATL_MODULE)))
  5767. return E_INVALIDARG;
  5768. #else
  5769. ATLASSERT(pM->cbSize == sizeof(_ATL_MODULE));
  5770. #endif
  5771. pM->m_pObjMap = p;
  5772. pM->m_hInst = pM->m_hInstTypeLib = pM->m_hInstResource = h;
  5773. pM->m_nLockCnt=0L;
  5774. pM->m_hHeap = NULL;
  5775. InitializeCriticalSection(&pM->m_csTypeInfoHolder);
  5776. InitializeCriticalSection(&pM->m_csWindowCreate);
  5777. InitializeCriticalSection(&pM->m_csObjMap);
  5778. #ifdef _ATL_DLL_IMPL
  5779. if (pM->cbSize > _nAtlModuleVer21Size)
  5780. #endif
  5781. {
  5782. pM->m_pCreateWndList = NULL;
  5783. pM->m_bDestroyHeap = true;
  5784. pM->m_dwHeaps = 0;
  5785. pM->m_nHeap = 0;
  5786. pM->m_phHeaps = NULL;
  5787. pM->m_pTermFuncs = NULL;
  5788. if (pM->m_pObjMap != NULL)
  5789. {
  5790. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  5791. while (pEntry->pclsid != NULL)
  5792. {
  5793. pEntry->pfnObjectMain(true); //initialize class resources
  5794. pEntry = _NextObjectMapEntry(pM, pEntry);
  5795. }
  5796. }
  5797. }
  5798. #ifdef _ATL_DLL_IMPL
  5799. if (pM->cbSize > _nAtlModuleVer30Size)
  5800. #endif
  5801. {
  5802. pM->m_nNextWindowID = 1;
  5803. }
  5804. return S_OK;
  5805. }
  5806. ATLINLINE ATLAPI AtlModuleRegisterClassObjects(_ATL_MODULE* pM, DWORD dwClsContext, DWORD dwFlags)
  5807. {
  5808. ATLASSERT(pM != NULL);
  5809. if (pM == NULL)
  5810. return E_INVALIDARG;
  5811. ATLASSERT(pM->m_pObjMap != NULL);
  5812. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  5813. HRESULT hRes = S_OK;
  5814. while (pEntry->pclsid != NULL && hRes == S_OK)
  5815. {
  5816. hRes = pEntry->RegisterClassObject(dwClsContext, dwFlags);
  5817. pEntry = _NextObjectMapEntry(pM, pEntry);
  5818. }
  5819. return hRes;
  5820. }
  5821. ATLINLINE ATLAPI AtlModuleRevokeClassObjects(_ATL_MODULE* pM)
  5822. {
  5823. ATLASSERT(pM != NULL);
  5824. if (pM == NULL)
  5825. return E_INVALIDARG;
  5826. ATLASSERT(pM->m_pObjMap != NULL);
  5827. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  5828. HRESULT hRes = S_OK;
  5829. while (pEntry->pclsid != NULL && hRes == S_OK)
  5830. {
  5831. hRes = pEntry->RevokeClassObject();
  5832. pEntry = _NextObjectMapEntry(pM, pEntry);
  5833. }
  5834. return hRes;
  5835. }
  5836. ATLINLINE ATLAPI AtlModuleGetClassObject(_ATL_MODULE* pM, REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  5837. {
  5838. ATLASSERT(pM != NULL);
  5839. if (pM == NULL)
  5840. return E_INVALIDARG;
  5841. ATLASSERT(pM->m_pObjMap != NULL);
  5842. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  5843. HRESULT hRes = S_OK;
  5844. if (ppv == NULL)
  5845. return E_POINTER;
  5846. *ppv = NULL;
  5847. while (pEntry->pclsid != NULL)
  5848. {
  5849. if ((pEntry->pfnGetClassObject != NULL) && InlineIsEqualGUID(rclsid, *pEntry->pclsid))
  5850. {
  5851. if (pEntry->pCF == NULL)
  5852. {
  5853. EnterCriticalSection(&pM->m_csObjMap);
  5854. if (pEntry->pCF == NULL)
  5855. hRes = pEntry->pfnGetClassObject(pEntry->pfnCreateInstance, IID_IUnknown, (LPVOID*)&pEntry->pCF);
  5856. LeaveCriticalSection(&pM->m_csObjMap);
  5857. }
  5858. if (pEntry->pCF != NULL)
  5859. hRes = pEntry->pCF->QueryInterface(riid, ppv);
  5860. break;
  5861. }
  5862. pEntry = _NextObjectMapEntry(pM, pEntry);
  5863. }
  5864. if (*ppv == NULL && hRes == S_OK)
  5865. hRes = CLASS_E_CLASSNOTAVAILABLE;
  5866. return hRes;
  5867. }
  5868. ATLINLINE ATLAPI AtlModuleTerm(_ATL_MODULE* pM)
  5869. {
  5870. ATLASSERT(pM != NULL);
  5871. if (pM == NULL)
  5872. return E_INVALIDARG;
  5873. ATLASSERT(pM->m_hInst != NULL);
  5874. if (pM->m_pObjMap != NULL)
  5875. {
  5876. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  5877. while (pEntry->pclsid != NULL)
  5878. {
  5879. if (pEntry->pCF != NULL)
  5880. pEntry->pCF->Release();
  5881. pEntry->pCF = NULL;
  5882. #ifdef _ATL_DLL_IMPL
  5883. if (pM->cbSize > _nAtlModuleVer21Size)
  5884. #endif
  5885. pEntry->pfnObjectMain(false); //cleanup class resources
  5886. pEntry = _NextObjectMapEntry(pM, pEntry);
  5887. }
  5888. }
  5889. DeleteCriticalSection(&pM->m_csTypeInfoHolder);
  5890. DeleteCriticalSection(&pM->m_csWindowCreate);
  5891. DeleteCriticalSection(&pM->m_csObjMap);
  5892. #ifdef _ATL_DLL_IMPL
  5893. if (pM->cbSize > _nAtlModuleVer21Size)
  5894. #endif
  5895. {
  5896. _ATL_TERMFUNC_ELEM* pElem = pM->m_pTermFuncs;
  5897. _ATL_TERMFUNC_ELEM* pNext = NULL;
  5898. while (pElem != NULL)
  5899. {
  5900. pElem->pFunc(pElem->dw);
  5901. pNext = pElem->pNext;
  5902. delete pElem;
  5903. pElem = pNext;
  5904. }
  5905. if (pM->m_hHeap != NULL && pM->m_bDestroyHeap)
  5906. {
  5907. #ifndef _ATL_NO_MP_HEAP
  5908. if (pM->m_phHeaps != NULL)
  5909. {
  5910. for (DWORD i = 0; i <= pM->m_dwHeaps; i++)
  5911. HeapDestroy(pM->m_phHeaps[i]);
  5912. }
  5913. #endif
  5914. HeapDestroy(pM->m_hHeap);
  5915. }
  5916. }
  5917. return S_OK;
  5918. }
  5919. ATLINLINE ATLAPI AtlModuleAddTermFunc(_ATL_MODULE* pM, _ATL_TERMFUNC* pFunc, DWORD_PTR dw)
  5920. {
  5921. HRESULT hr = S_OK;
  5922. _ATL_TERMFUNC_ELEM* pNew = NULL;
  5923. ATLTRY(pNew = new _ATL_TERMFUNC_ELEM);
  5924. if (pNew == NULL)
  5925. hr = E_OUTOFMEMORY;
  5926. else
  5927. {
  5928. pNew->pFunc = pFunc;
  5929. pNew->dw = dw;
  5930. EnterCriticalSection(&pM->m_csStaticDataInit);
  5931. pNew->pNext = pM->m_pTermFuncs;
  5932. pM->m_pTermFuncs = pNew;
  5933. LeaveCriticalSection(&pM->m_csStaticDataInit);
  5934. }
  5935. return hr;
  5936. }
  5937. ATLINLINE ATLAPI AtlRegisterClassCategoriesHelper( REFCLSID clsid,
  5938. const struct _ATL_CATMAP_ENTRY* pCatMap, BOOL bRegister )
  5939. {
  5940. CComPtr< ICatRegister > pCatRegister;
  5941. HRESULT hResult;
  5942. const struct _ATL_CATMAP_ENTRY* pEntry;
  5943. CATID catid;
  5944. if( pCatMap == NULL )
  5945. {
  5946. return( S_OK );
  5947. }
  5948. hResult = CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL,
  5949. CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pCatRegister );
  5950. if( FAILED( hResult ) )
  5951. {
  5952. // Since not all systems have the category manager installed, we'll allow
  5953. // the registration to succeed even though we didn't register our
  5954. // categories. If you really want to register categories on a system
  5955. // without the category manager, you can either manually add the
  5956. // appropriate entries to your registry script (.rgs), or you can
  5957. // redistribute comcat.dll.
  5958. return( S_OK );
  5959. }
  5960. hResult = S_OK;
  5961. pEntry = pCatMap;
  5962. while( pEntry->iType != _ATL_CATMAP_ENTRY_END )
  5963. {
  5964. catid = *pEntry->pcatid;
  5965. if( bRegister )
  5966. {
  5967. if( pEntry->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED )
  5968. {
  5969. hResult = pCatRegister->RegisterClassImplCategories( clsid, 1,
  5970. &catid );
  5971. }
  5972. else
  5973. {
  5974. ATLASSERT( pEntry->iType == _ATL_CATMAP_ENTRY_REQUIRED );
  5975. hResult = pCatRegister->RegisterClassReqCategories( clsid, 1,
  5976. &catid );
  5977. }
  5978. if( FAILED( hResult ) )
  5979. {
  5980. return( hResult );
  5981. }
  5982. }
  5983. else
  5984. {
  5985. if( pEntry->iType == _ATL_CATMAP_ENTRY_IMPLEMENTED )
  5986. {
  5987. pCatRegister->UnRegisterClassImplCategories( clsid, 1, &catid );
  5988. }
  5989. else
  5990. {
  5991. ATLASSERT( pEntry->iType == _ATL_CATMAP_ENTRY_REQUIRED );
  5992. pCatRegister->UnRegisterClassReqCategories( clsid, 1, &catid );
  5993. }
  5994. }
  5995. pEntry++;
  5996. }
  5997. return( S_OK );
  5998. }
  5999. ATLINLINE ATLAPI AtlModuleRegisterServer(_ATL_MODULE* pM, BOOL bRegTypeLib, const CLSID* pCLSID)
  6000. {
  6001. ATLASSERT(pM != NULL);
  6002. if (pM == NULL)
  6003. return E_INVALIDARG;
  6004. ATLASSERT(pM->m_hInst != NULL);
  6005. ATLASSERT(pM->m_pObjMap != NULL);
  6006. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  6007. HRESULT hRes = S_OK;
  6008. for (;pEntry->pclsid != NULL; pEntry = _NextObjectMapEntry(pM, pEntry))
  6009. {
  6010. if (pCLSID == NULL)
  6011. {
  6012. if (pEntry->pfnGetObjectDescription != NULL &&
  6013. pEntry->pfnGetObjectDescription() != NULL)
  6014. continue;
  6015. }
  6016. else
  6017. {
  6018. if (!IsEqualGUID(*pCLSID, *pEntry->pclsid))
  6019. continue;
  6020. }
  6021. hRes = pEntry->pfnUpdateRegistry(TRUE);
  6022. if (FAILED(hRes))
  6023. break;
  6024. if (pM->cbSize == sizeof(_ATL_MODULE))
  6025. {
  6026. hRes = AtlRegisterClassCategoriesHelper( *pEntry->pclsid,
  6027. pEntry->pfnGetCategoryMap(), TRUE );
  6028. if (FAILED(hRes))
  6029. break;
  6030. }
  6031. }
  6032. if (SUCCEEDED(hRes) && bRegTypeLib)
  6033. hRes = AtlModuleRegisterTypeLib(pM, 0);
  6034. return hRes;
  6035. }
  6036. ATLINLINE ATLAPI AtlModuleUnregisterServerEx(_ATL_MODULE* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
  6037. {
  6038. ATLASSERT(pM != NULL);
  6039. if (pM == NULL)
  6040. return E_INVALIDARG;
  6041. ATLASSERT(pM->m_hInst != NULL);
  6042. ATLASSERT(pM->m_pObjMap != NULL);
  6043. _ATL_OBJMAP_ENTRY* pEntry = pM->m_pObjMap;
  6044. for (;pEntry->pclsid != NULL; pEntry = _NextObjectMapEntry(pM, pEntry))
  6045. {
  6046. if (pCLSID == NULL)
  6047. {
  6048. if (pEntry->pfnGetObjectDescription != NULL
  6049. && pEntry->pfnGetObjectDescription() != NULL)
  6050. continue;
  6051. }
  6052. else
  6053. {
  6054. if (!IsEqualGUID(*pCLSID, *pEntry->pclsid))
  6055. continue;
  6056. }
  6057. pEntry->pfnUpdateRegistry(FALSE); //unregister
  6058. if (pM->cbSize == sizeof(_ATL_MODULE) && pEntry->pfnGetCategoryMap != NULL)
  6059. AtlRegisterClassCategoriesHelper( *pEntry->pclsid,
  6060. pEntry->pfnGetCategoryMap(), FALSE );
  6061. }
  6062. if (bUnRegTypeLib)
  6063. AtlModuleUnRegisterTypeLib(pM, 0);
  6064. return S_OK;
  6065. }
  6066. ATLINLINE ATLAPI AtlModuleUnregisterServer(_ATL_MODULE* pM, const CLSID* pCLSID)
  6067. {
  6068. return AtlModuleUnregisterServerEx(pM, FALSE, pCLSID);
  6069. }
  6070. ATLINLINE ATLAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULE* pM, LPCOLESTR lpszRes,
  6071. BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg)
  6072. {
  6073. USES_CONVERSION;
  6074. ATLASSERT(pM != NULL);
  6075. HRESULT hRes = S_OK;
  6076. CComPtr<IRegistrar> p;
  6077. if (pReg != NULL)
  6078. p = pReg;
  6079. else
  6080. {
  6081. hRes = CoCreateInstance(CLSID_Registrar, NULL,
  6082. CLSCTX_INPROC_SERVER, IID_IRegistrar, (void**)&p);
  6083. }
  6084. if (SUCCEEDED(hRes))
  6085. {
  6086. TCHAR szModule[_MAX_PATH];
  6087. GetModuleFileName(pM->m_hInst, szModule, _MAX_PATH);
  6088. LPOLESTR pszModule;
  6089. if ((pM->m_hInst == NULL) || (pM->m_hInst == GetModuleHandle(NULL))) // register as EXE
  6090. {
  6091. // Convert to short path to work around bug in NT4's CreateProcess
  6092. TCHAR szModuleShort[_MAX_PATH];
  6093. int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH);
  6094. if (cbShortName == _MAX_PATH)
  6095. return E_OUTOFMEMORY;
  6096. pszModule = (cbShortName == 0 || cbShortName == ERROR_INVALID_PARAMETER) ? T2OLE(szModule) : T2OLE(szModuleShort);
  6097. }
  6098. else
  6099. pszModule = T2OLE(szModule);
  6100. int nLen = ocslen(pszModule);
  6101. LPOLESTR pszModuleQuote = (LPOLESTR)alloca((nLen*2+1)*sizeof(OLECHAR));
  6102. CComModule::ReplaceSingleQuote(pszModuleQuote, pszModule);
  6103. p->AddReplacement(OLESTR("Module"), pszModuleQuote);
  6104. if (NULL != pMapEntries)
  6105. {
  6106. while (NULL != pMapEntries->szKey)
  6107. {
  6108. ATLASSERT(NULL != pMapEntries->szData);
  6109. p->AddReplacement((LPOLESTR)pMapEntries->szKey, (LPOLESTR)pMapEntries->szData);
  6110. pMapEntries++;
  6111. }
  6112. }
  6113. LPCOLESTR szType = OLESTR("REGISTRY");
  6114. if (DWORD_PTR(lpszRes)<=0xffff)
  6115. {
  6116. if (bRegister)
  6117. hRes = p->ResourceRegister(pszModule, ((UINT)LOWORD((DWORD_PTR)lpszRes)), szType);
  6118. else
  6119. hRes = p->ResourceUnregister(pszModule, ((UINT)LOWORD((DWORD_PTR)lpszRes)), szType);
  6120. }
  6121. else
  6122. {
  6123. if (bRegister)
  6124. hRes = p->ResourceRegisterSz(pszModule, lpszRes, szType);
  6125. else
  6126. hRes = p->ResourceUnregisterSz(pszModule, lpszRes, szType);
  6127. }
  6128. }
  6129. return hRes;
  6130. }
  6131. /////////////////////////////////////////////////////////////////////////////
  6132. // TypeLib Support
  6133. ATLINLINE ATLAPI AtlModuleLoadTypeLib(_ATL_MODULE* pM, LPCOLESTR lpszIndex, BSTR* pbstrPath, ITypeLib** ppTypeLib)
  6134. {
  6135. *pbstrPath = NULL;
  6136. *ppTypeLib = NULL;
  6137. ATLASSERT(pM != NULL);
  6138. USES_CONVERSION;
  6139. ATLASSERT(pM->m_hInstTypeLib != NULL);
  6140. TCHAR szModule[_MAX_PATH+10];
  6141. GetModuleFileName(pM->m_hInstTypeLib, szModule, _MAX_PATH);
  6142. if (lpszIndex != NULL)
  6143. lstrcat(szModule, OLE2CT(lpszIndex));
  6144. LPOLESTR lpszModule = T2OLE(szModule);
  6145. HRESULT hr = LoadTypeLib(lpszModule, ppTypeLib);
  6146. if (!SUCCEEDED(hr))
  6147. {
  6148. // typelib not in module, try <module>.tlb instead
  6149. LPTSTR lpszExt = NULL;
  6150. LPTSTR lpsz;
  6151. for (lpsz = szModule; *lpsz != NULL; lpsz = CharNext(lpsz))
  6152. {
  6153. if (*lpsz == _T('.'))
  6154. lpszExt = lpsz;
  6155. }
  6156. if (lpszExt == NULL)
  6157. lpszExt = lpsz;
  6158. lstrcpy(lpszExt, _T(".tlb"));
  6159. lpszModule = T2OLE(szModule);
  6160. hr = LoadTypeLib(lpszModule, ppTypeLib);
  6161. }
  6162. if (SUCCEEDED(hr))
  6163. *pbstrPath = OLE2BSTR(lpszModule);
  6164. return hr;
  6165. }
  6166. ATLINLINE ATLAPI AtlModuleUnRegisterTypeLib(_ATL_MODULE* pM, LPCOLESTR lpszIndex)
  6167. {
  6168. typedef HRESULT (WINAPI *PFNRTL)(REFGUID, WORD, WORD, LCID, SYSKIND);
  6169. CComBSTR bstrPath;
  6170. CComPtr<ITypeLib> pTypeLib;
  6171. HRESULT hr = AtlModuleLoadTypeLib(pM, lpszIndex, &bstrPath, &pTypeLib);
  6172. if (SUCCEEDED(hr))
  6173. {
  6174. TLIBATTR* ptla;
  6175. HRESULT hr = pTypeLib->GetLibAttr(&ptla);
  6176. if (SUCCEEDED(hr))
  6177. {
  6178. HINSTANCE h = LoadLibrary(_T("oleaut32.dll"));
  6179. if (h != NULL)
  6180. {
  6181. PFNRTL pfn = (PFNRTL) GetProcAddress(h, "UnRegisterTypeLib");
  6182. if (pfn != NULL)
  6183. hr = pfn(ptla->guid, ptla->wMajorVerNum, ptla->wMinorVerNum, ptla->lcid, ptla->syskind);
  6184. FreeLibrary(h);
  6185. }
  6186. pTypeLib->ReleaseTLibAttr(ptla);
  6187. }
  6188. }
  6189. return hr;
  6190. }
  6191. ATLINLINE ATLAPI AtlModuleRegisterTypeLib(_ATL_MODULE* pM, LPCOLESTR lpszIndex)
  6192. {
  6193. CComBSTR bstrPath;
  6194. CComPtr<ITypeLib> pTypeLib;
  6195. HRESULT hr = AtlModuleLoadTypeLib(pM, lpszIndex, &bstrPath, &pTypeLib);
  6196. if (SUCCEEDED(hr))
  6197. {
  6198. OLECHAR szDir[_MAX_PATH];
  6199. ocscpy(szDir, bstrPath);
  6200. szDir[AtlGetDirLen(szDir)] = 0;
  6201. hr = ::RegisterTypeLib(pTypeLib, bstrPath, szDir);
  6202. }
  6203. return hr;
  6204. }
  6205. ATLINLINE ATLAPI_(DWORD) AtlGetVersion(void* /* pReserved */)
  6206. {
  6207. return _ATL_VER;
  6208. }
  6209. ATLINLINE ATLAPI_(void) AtlModuleAddCreateWndData(_ATL_MODULE* pM, _AtlCreateWndData* pData, void* pObject)
  6210. {
  6211. pData->m_pThis = pObject;
  6212. pData->m_dwThreadID = ::GetCurrentThreadId();
  6213. ::EnterCriticalSection(&pM->m_csWindowCreate);
  6214. pData->m_pNext = pM->m_pCreateWndList;
  6215. pM->m_pCreateWndList = pData;
  6216. ::LeaveCriticalSection(&pM->m_csWindowCreate);
  6217. }
  6218. ATLINLINE ATLAPI_(void*) AtlModuleExtractCreateWndData(_ATL_MODULE* pM)
  6219. {
  6220. void* pv = NULL;
  6221. ::EnterCriticalSection(&pM->m_csWindowCreate);
  6222. _AtlCreateWndData* pEntry = pM->m_pCreateWndList;
  6223. if(pEntry != NULL)
  6224. {
  6225. DWORD dwThreadID = ::GetCurrentThreadId();
  6226. _AtlCreateWndData* pPrev = NULL;
  6227. while(pEntry != NULL)
  6228. {
  6229. if(pEntry->m_dwThreadID == dwThreadID)
  6230. {
  6231. if(pPrev == NULL)
  6232. pM->m_pCreateWndList = pEntry->m_pNext;
  6233. else
  6234. pPrev->m_pNext = pEntry->m_pNext;
  6235. pv = pEntry->m_pThis;
  6236. break;
  6237. }
  6238. pPrev = pEntry;
  6239. pEntry = pEntry->m_pNext;
  6240. }
  6241. }
  6242. ::LeaveCriticalSection(&pM->m_csWindowCreate);
  6243. return pv;
  6244. }
  6245. /////////////////////////////////////////////////////////////////////////////
  6246. // General DLL Version Helpers
  6247. inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
  6248. {
  6249. ATLASSERT(pDllVersionInfo != NULL);
  6250. if(::IsBadWritePtr(pDllVersionInfo, sizeof(DWORD)))
  6251. return E_INVALIDARG;
  6252. // We must get this function explicitly because some DLLs don't implement it.
  6253. DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL, "DllGetVersion");
  6254. if(pfnDllGetVersion == NULL)
  6255. return E_NOTIMPL;
  6256. return (*pfnDllGetVersion)(pDllVersionInfo);
  6257. }
  6258. inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
  6259. {
  6260. HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
  6261. if(hInstDLL == NULL)
  6262. return E_FAIL;
  6263. HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
  6264. ::FreeLibrary(hInstDLL);
  6265. return hRet;
  6266. }
  6267. // Common Control Versions:
  6268. // Win95/WinNT 4.0 maj=4 min=00
  6269. // IE 3.x maj=4 min=70
  6270. // IE 4.0 maj=4 min=71
  6271. inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
  6272. {
  6273. ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
  6274. if(::IsBadWritePtr(pdwMajor, sizeof(DWORD)) || ::IsBadWritePtr(pdwMinor, sizeof(DWORD)))
  6275. return E_INVALIDARG;
  6276. DLLVERSIONINFO dvi;
  6277. ::ZeroMemory(&dvi, sizeof(dvi));
  6278. dvi.cbSize = sizeof(dvi);
  6279. HRESULT hRet = AtlGetDllVersion(_T("comctl32.dll"), &dvi);
  6280. if(SUCCEEDED(hRet))
  6281. {
  6282. *pdwMajor = dvi.dwMajorVersion;
  6283. *pdwMinor = dvi.dwMinorVersion;
  6284. }
  6285. else if(hRet == E_NOTIMPL)
  6286. {
  6287. // If DllGetVersion is not there, then the DLL is a version
  6288. // previous to the one shipped with IE 3.x
  6289. *pdwMajor = 4;
  6290. *pdwMinor = 0;
  6291. hRet = S_OK;
  6292. }
  6293. return hRet;
  6294. }
  6295. // Shell Versions:
  6296. // Win95/WinNT 4.0 maj=4 min=00
  6297. // IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00
  6298. // IE 4.0 with Web Integrated Desktop maj=4 min=71
  6299. // IE 4.01 with Web Integrated Desktop maj=4 min=72
  6300. inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
  6301. {
  6302. ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
  6303. if(::IsBadWritePtr(pdwMajor, sizeof(DWORD)) || ::IsBadWritePtr(pdwMinor, sizeof(DWORD)))
  6304. return E_INVALIDARG;
  6305. DLLVERSIONINFO dvi;
  6306. ::ZeroMemory(&dvi, sizeof(dvi));
  6307. dvi.cbSize = sizeof(dvi);
  6308. HRESULT hRet = AtlGetDllVersion(_T("shell32.dll"), &dvi);
  6309. if(SUCCEEDED(hRet))
  6310. {
  6311. *pdwMajor = dvi.dwMajorVersion;
  6312. *pdwMinor = dvi.dwMinorVersion;
  6313. }
  6314. else if(hRet == E_NOTIMPL)
  6315. {
  6316. // If DllGetVersion is not there, then the DLL is a version
  6317. // previous to the one shipped with IE 4.x
  6318. *pdwMajor = 4;
  6319. *pdwMinor = 0;
  6320. hRet = S_OK;
  6321. }
  6322. return hRet;
  6323. }
  6324. #ifndef _ATL_DLL_IMPL
  6325. }; //namespace ATL
  6326. #endif
  6327. //Prevent pulling in second time
  6328. #undef _ATLBASE_IMPL
  6329. #endif // _ATLBASE_IMPL
  6330. /////////////////////////////////////////////////////////////////////////////