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.

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