Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6384 lines
179 KiB

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