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.

342 lines
7.3 KiB

  1. //+----------------------------------------------------------------------------
  2. // File: main.cxx
  3. //
  4. // Synopsis: This file contains the core routines and globals for creating
  5. // LICMGR.DLL
  6. //
  7. //-----------------------------------------------------------------------------
  8. // Includes -------------------------------------------------------------------
  9. #include <mgr.hxx>
  10. #include <factory.hxx>
  11. // Globals --------------------------------------------------------------------
  12. BEGIN_PROCESS_ATTACH
  13. ATTACH_METHOD(ProcessAttachMIME64)
  14. END_PROCESS_ATTACH
  15. BEGIN_PROCESS_DETACH
  16. END_PROCESS_DETACH
  17. BEGIN_THREAD_ATTACH
  18. END_THREAD_ATTACH
  19. BEGIN_THREAD_DETACH
  20. END_THREAD_DETACH
  21. BEGIN_PROCESS_PASSIVATE
  22. END_PROCESS_PASSIVATE
  23. BEGIN_THREAD_PASSIVATE
  24. END_THREAD_PASSIVATE
  25. BEGIN_CLASS_FACTORIES
  26. FACTORY(CLSID_LicenseManager, LicenseManagerFactory, NULL)
  27. END_CLASS_FACTORIES
  28. DEFINE_REGISTRY_SECKEY(LicenseManagerCLSID, CLSID, {5220cb21-c88d-11cf-b347-00aa00a28331})
  29. DEFAULT_VALUE(Microsoft Licensed Class Manager 1.0)
  30. BEGIN_SUBKEY(Implemented Categories)
  31. BEGIN_SUBKEY({7DD95801-9882-11CF-9FA9-00AA006C42C4})
  32. END_SUBKEY
  33. BEGIN_SUBKEY({7DD95802-9882-11CF-9FA9-00AA006C42C4})
  34. END_SUBKEY
  35. END_SUBKEY
  36. BEGIN_SUBKEY(InprocServer32)
  37. DEFAULT_VALUE(<m>)
  38. BEGIN_NAMED_VALUES
  39. NAMED_VALUE(ThreadingModel, Apartment)
  40. END_NAMED_VALUES
  41. END_SUBKEY
  42. BEGIN_SUBKEY(MiscStatus)
  43. DEFAULT_VALUE(0)
  44. END_SUBKEY
  45. BEGIN_SUBKEY(ProgID)
  46. DEFAULT_VALUE(License.Manager.1)
  47. END_SUBKEY
  48. BEGIN_SUBKEY(Version)
  49. DEFAULT_VALUE(1.0)
  50. END_SUBKEY
  51. BEGIN_SUBKEY(VersionIndependentProgID)
  52. DEFAULT_VALUE(License.Manager)
  53. END_SUBKEY
  54. END_REGISTRY_KEY
  55. DEFINE_REGISTRY_KEY(LicenseManagerProgID, License.Manager.1)
  56. DEFAULT_VALUE(Microsoft Licensed Class Manager 1.0)
  57. BEGIN_SUBKEY(CLSID)
  58. DEFAULT_VALUE({5220cb21-c88d-11cf-b347-00aa00a28331})
  59. END_SUBKEY
  60. END_REGISTRY_KEY
  61. DEFINE_REGISTRY_KEY(LicenseManagerVProgID, License.Manager)
  62. DEFAULT_VALUE(Microsoft Licensed Class Manager)
  63. BEGIN_SUBKEY(CurVer)
  64. DEFAULT_VALUE(License.Manager.1)
  65. END_SUBKEY
  66. END_REGISTRY_KEY
  67. BEGIN_REGISTRY_KEYS
  68. REGISTRY_KEY(LicenseManagerCLSID)
  69. REGISTRY_KEY(LicenseManagerProgID)
  70. REGISTRY_KEY(LicenseManagerVProgID)
  71. END_REGISTRY_KEYS
  72. //+----------------------------------------------------------------------------
  73. // Function: AllocateThreadState
  74. //
  75. // Synopsis:
  76. //
  77. //-----------------------------------------------------------------------------
  78. HRESULT
  79. AllocateThreadState(
  80. THREADSTATE ** ppts)
  81. {
  82. Assert(ppts);
  83. *ppts = new THREADSTATE;
  84. if (!*ppts)
  85. {
  86. return E_OUTOFMEMORY;
  87. }
  88. memset(*ppts, 0, sizeof(THREADSTATE));
  89. return S_OK;
  90. }
  91. //+----------------------------------------------------------------------------
  92. //
  93. // Function: LicensedClassManagerFactory
  94. //
  95. // Synopsis:
  96. //
  97. // Arguments:
  98. //
  99. // Returns:
  100. //
  101. //-----------------------------------------------------------------------------
  102. HRESULT
  103. LicenseManagerFactory(
  104. IUnknown * pUnkOuter,
  105. REFIID riid,
  106. void ** ppvObj)
  107. {
  108. CLicenseManager * plcmgr = new CLicenseManager(pUnkOuter);
  109. if (!plcmgr)
  110. {
  111. *ppvObj = NULL;
  112. return E_OUTOFMEMORY;
  113. }
  114. return plcmgr->PrivateQueryInterface(riid, ppvObj);
  115. }
  116. //+----------------------------------------------------------------------------
  117. //
  118. // Member: CLicenseManager
  119. //
  120. // Synopsis:
  121. //
  122. // Arguments:
  123. //
  124. // Returns:
  125. //
  126. //-----------------------------------------------------------------------------
  127. CLicenseManager::CLicenseManager(
  128. IUnknown * pUnkOuter)
  129. : CComponent(pUnkOuter)
  130. {
  131. _pUnkSite = NULL;
  132. _fDirty = FALSE;
  133. _fLoaded = FALSE;
  134. _fPersistPBag = FALSE;
  135. _fPersistStream = FALSE;
  136. _guidLPK = GUID_NULL;
  137. }
  138. //+----------------------------------------------------------------------------
  139. //
  140. // Member: ~CLicenseManager
  141. //
  142. // Synopsis:
  143. //
  144. // Arguments:
  145. //
  146. // Returns:
  147. //
  148. //-----------------------------------------------------------------------------
  149. CLicenseManager::~CLicenseManager()
  150. {
  151. int i;
  152. for (i = _aryLic.Size()-1; i >= 0; i--)
  153. {
  154. ::SysFreeString(_aryLic[i].bstrLic);
  155. ::SRelease(_aryLic[i].pcf2);
  156. }
  157. ::SRelease(_pUnkSite);
  158. }
  159. //+----------------------------------------------------------------------------
  160. //
  161. // Member: SetSite
  162. //
  163. // Synopsis:
  164. //
  165. // Arguments:
  166. //
  167. // Returns:
  168. //
  169. //-----------------------------------------------------------------------------
  170. STDMETHODIMP
  171. CLicenseManager::SetSite(
  172. IUnknown * pUnkSite)
  173. {
  174. ::SClear(&_pUnkSite);
  175. _pUnkSite = pUnkSite;
  176. if (_pUnkSite)
  177. {
  178. _pUnkSite->AddRef();
  179. }
  180. return S_OK;
  181. }
  182. //+----------------------------------------------------------------------------
  183. //
  184. // Member: GetSite
  185. //
  186. // Synopsis:
  187. //
  188. // Arguments:
  189. //
  190. // Returns:
  191. //
  192. //-----------------------------------------------------------------------------
  193. STDMETHODIMP
  194. CLicenseManager::GetSite(
  195. REFIID riid,
  196. void ** ppvSite)
  197. {
  198. HRESULT hr;
  199. if (!ppvSite)
  200. return E_INVALIDARG;
  201. if (_pUnkSite)
  202. {
  203. hr = _pUnkSite->QueryInterface(riid, ppvSite);
  204. }
  205. else
  206. {
  207. *ppvSite = NULL;
  208. hr = E_FAIL;
  209. }
  210. return hr;
  211. }
  212. //+----------------------------------------------------------------------------
  213. //
  214. // Member: SetClientSite
  215. //
  216. // Synopsis:
  217. //
  218. // Arguments:
  219. //
  220. // Returns:
  221. //
  222. //-----------------------------------------------------------------------------
  223. STDMETHODIMP
  224. CLicenseManager::SetClientSite(
  225. IOleClientSite * pClientSite)
  226. {
  227. return SetSite(pClientSite);
  228. }
  229. //+----------------------------------------------------------------------------
  230. //
  231. // Member: GetClientSite
  232. //
  233. // Synopsis:
  234. //
  235. // Arguments:
  236. //
  237. // Returns:
  238. //
  239. //-----------------------------------------------------------------------------
  240. STDMETHODIMP
  241. CLicenseManager::GetClientSite(
  242. IOleClientSite ** ppClientSite)
  243. {
  244. return GetSite(IID_IOleClientSite, (void **)ppClientSite);
  245. }
  246. //+----------------------------------------------------------------------------
  247. //
  248. // Member: PrivateQueryInterface
  249. //
  250. // Synopsis:
  251. //
  252. // Arguments:
  253. //
  254. // Returns:
  255. //
  256. //-----------------------------------------------------------------------------
  257. HRESULT
  258. CLicenseManager::PrivateQueryInterface(
  259. REFIID riid,
  260. void ** ppvObj)
  261. {
  262. if (riid == IID_IObjectWithSite)
  263. *ppvObj = (IObjectWithSite *)this;
  264. else if (riid == IID_IOleObject)
  265. *ppvObj = (IOleObject *)this;
  266. else if (riid == IID_ILicensedClassManager)
  267. *ppvObj = (ILicensedClassManager *)this;
  268. else if (riid == IID_ILocalRegistry)
  269. *ppvObj = (ILocalRegistry *)this;
  270. else if (riid == IID_IRequireClasses)
  271. *ppvObj = (IRequireClasses *)this;
  272. else if (riid == IID_IPersistStream && !_fPersistPBag)
  273. {
  274. _fPersistStream = TRUE;
  275. *ppvObj = (IPersistStream *)this;
  276. }
  277. else if (riid == IID_IPersistStreamInit && !_fPersistPBag)
  278. {
  279. _fPersistStream = TRUE;
  280. *ppvObj = (IPersistStreamInit *)this;
  281. }
  282. else if (riid == IID_IPersistPropertyBag && !_fPersistStream)
  283. {
  284. _fPersistPBag = TRUE;
  285. *ppvObj = (IPersistPropertyBag *)this;
  286. }
  287. if (*ppvObj)
  288. return S_OK;
  289. else
  290. return parent::PrivateQueryInterface(riid, ppvObj);
  291. }