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

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