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

442 lines
9.9 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Class: CAdvBndCF
  4. //
  5. // Synopsis: Class Factory for CAdvBnd
  6. //
  7. // Interfaces: IUnknown - QueryInterface, AddRef, Release
  8. // IClassFactory - CreateInstance
  9. //
  10. // History: 21-Nov-92 SarahJ Created
  11. //
  12. //--------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <advbnd.hxx>
  16. const GUID CLSID_AdvBnd =
  17. {0x99999999,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x48}};
  18. //+-------------------------------------------------------------------
  19. //
  20. // Member: CAdvBndCF::CAdvBndCF()
  21. //
  22. // Synopsis: The constructor for CAdvBnd.
  23. //
  24. // Arguments: None
  25. //
  26. // History: 21-Nov-92 SarahJ Created
  27. //
  28. //--------------------------------------------------------------------
  29. CAdvBndCF::CAdvBndCF() : _cRefs(1), _pCF(NULL)
  30. {
  31. return;
  32. }
  33. //+-------------------------------------------------------------------
  34. //
  35. // Member: CAdvBnd::~CAdvBndObj()
  36. //
  37. // Synopsis: The destructor for CAdvBnd.
  38. //
  39. // History: 21-Nov-92 SarahJ Created
  40. //
  41. //--------------------------------------------------------------------
  42. CAdvBndCF::~CAdvBndCF()
  43. {
  44. if (_pCF)
  45. {
  46. _pCF->Release();
  47. }
  48. return;
  49. }
  50. //+-------------------------------------------------------------------
  51. //
  52. // Method: CAdvBndCF::QueryInterface
  53. //
  54. // Synopsis: Only IUnknown and IClassFactory supported
  55. //
  56. //--------------------------------------------------------------------
  57. STDMETHODIMP CAdvBndCF::QueryInterface(REFIID iid, void FAR * FAR * ppv)
  58. {
  59. if (IsEqualIID(iid, IID_IUnknown) ||
  60. IsEqualIID(iid, IID_IClassFactory))
  61. {
  62. *ppv = (IUnknown *) this;
  63. AddRef();
  64. return S_OK;
  65. }
  66. else
  67. {
  68. *ppv = NULL;
  69. return E_NOINTERFACE;
  70. }
  71. }
  72. STDMETHODIMP_(ULONG) CAdvBndCF::AddRef(void)
  73. {
  74. return ++_cRefs;
  75. }
  76. STDMETHODIMP_(ULONG) CAdvBndCF::Release(void)
  77. {
  78. if (--_cRefs == 0)
  79. {
  80. delete this;
  81. }
  82. return _cRefs;
  83. }
  84. //+-------------------------------------------------------------------
  85. //
  86. // Method: CAdvBndCF::CreateInstance
  87. //
  88. // Synopsis: This is called by Binding process to create the
  89. // actual class object
  90. //
  91. //--------------------------------------------------------------------
  92. STDMETHODIMP CAdvBndCF::CreateInstance(
  93. IUnknown FAR* pUnkOuter,
  94. REFIID iidInterface,
  95. void FAR* FAR* ppv)
  96. {
  97. Display(TEXT("CAdvBndCF::CreateInstance called\n"));
  98. HRESULT hresult;
  99. if (!_pCF)
  100. {
  101. // Load the class object for the class to aggregate.
  102. hresult = CoGetClassObject(CLSID_BasicBnd, CLSCTX_SERVER, NULL,
  103. IID_IClassFactory, (void **) &_pCF);
  104. Win4Assert(SUCCEEDED(hresult)
  105. && "CAdvBnd::CAdvBnd CoGetClassObject failed");
  106. if (FAILED(hresult))
  107. {
  108. return hresult;
  109. }
  110. }
  111. if (pUnkOuter != NULL)
  112. {
  113. return E_FAIL;
  114. }
  115. CAdvBnd * lpcBB = new FAR CAdvBnd((IClassFactory *) _pCF);
  116. if (lpcBB == NULL)
  117. {
  118. return E_OUTOFMEMORY;
  119. }
  120. hresult = lpcBB->QueryInterface(iidInterface, ppv);
  121. lpcBB->Release();
  122. return hresult;
  123. }
  124. STDMETHODIMP CAdvBndCF::LockServer(BOOL fLock)
  125. {
  126. if (fLock)
  127. GlobalRefs(TRUE);
  128. else
  129. GlobalRefs(FALSE);
  130. return S_OK;
  131. }
  132. //+-------------------------------------------------------------------
  133. //
  134. // Member: CAdvBnd::CAdvBnd()
  135. //
  136. // Synopsis: The constructor for CAdvBnd. I
  137. //
  138. // Arguments: None
  139. //
  140. // History: 21-Nov-92 SarahJ Created
  141. //
  142. //--------------------------------------------------------------------
  143. CAdvBnd::CAdvBnd(IClassFactory *pcfBase) : _xiunk(), _dwRegister(0), _cRefs(1)
  144. {
  145. HRESULT hresult = pcfBase->CreateInstance((IUnknown *) this, IID_IUnknown,
  146. (void **) &_xiunk);
  147. GlobalRefs(TRUE);
  148. }
  149. //+-------------------------------------------------------------------
  150. //
  151. // Member: CAdvBnd::~CAdvBndObj()
  152. //
  153. // Synopsis: The destructor for CAdvBnd.
  154. //
  155. // History: 21-Nov-92 SarahJ Created
  156. //
  157. //--------------------------------------------------------------------
  158. CAdvBnd::~CAdvBnd()
  159. {
  160. Display(TEXT("CAdvBndCF::~CAdvBnd called\n"));
  161. if (_dwRegister != 0)
  162. {
  163. // Get the running object table
  164. IRunningObjectTable *prot;
  165. HRESULT hresult = GetRunningObjectTable(0, &prot);
  166. Win4Assert(SUCCEEDED(hresult)
  167. && "CAdvBnd::~CAdvBnd GetRunningObjectTable failed");
  168. hresult = prot->Revoke(_dwRegister);
  169. Win4Assert(SUCCEEDED(hresult)
  170. && "CAdvBnd::~CAdvBnd Revoke failed");
  171. prot->Release();
  172. }
  173. GlobalRefs(FALSE);
  174. }
  175. //+-------------------------------------------------------------------
  176. //
  177. // Member: CAdvBnd::QueryInterface
  178. //
  179. // Returns: SUCCESS_SUCCCESS
  180. //
  181. // History: 21-Nov-92 SarahJ Created
  182. //
  183. //--------------------------------------------------------------------
  184. STDMETHODIMP CAdvBnd::QueryInterface(REFIID iid, void ** ppunk)
  185. {
  186. Display(TEXT("CAdvBnd::QueryInterface called\n"));
  187. if (IsEqualIID(iid, IID_IUnknown))
  188. {
  189. *ppunk = (IUnknown *) this;
  190. AddRef();
  191. return S_OK;
  192. }
  193. else if ((IsEqualIID(iid, IID_IPersistFile)) ||
  194. (IsEqualIID(iid, IID_IPersist)))
  195. {
  196. *ppunk = (IPersistFile *) this;
  197. AddRef();
  198. return S_OK;
  199. }
  200. return _xiunk->QueryInterface(iid, ppunk);
  201. }
  202. STDMETHODIMP_(ULONG) CAdvBnd::AddRef(void)
  203. {
  204. return ++_cRefs;
  205. }
  206. STDMETHODIMP_(ULONG) CAdvBnd::Release(void)
  207. {
  208. if (--_cRefs == 0)
  209. {
  210. delete this;
  211. }
  212. return _cRefs;
  213. }
  214. //+-------------------------------------------------------------------
  215. //
  216. // Member: CAdvBnd::Load
  217. //
  218. // Synopsis: IPeristFile interface - needed 'cause we bind with
  219. // file moniker and BindToObject insists on calling this
  220. //
  221. // History: 21-Nov-92 SarahJ Created
  222. //
  223. //--------------------------------------------------------------------
  224. STDMETHODIMP CAdvBnd::Load(LPCOLESTR lpszFileName, DWORD grfMode)
  225. {
  226. Display(TEXT("CAdvBndCF::Load called\n"));
  227. // Forward call to delegated class
  228. IPersistFile *pipfile;
  229. HRESULT hresult = _xiunk->QueryInterface(IID_IPersistFile,
  230. (void **) &pipfile);
  231. hresult = pipfile->Load(lpszFileName, grfMode);
  232. pipfile->Release();
  233. if (FAILED(hresult))
  234. {
  235. // Make sure delegated too class liked what it got/
  236. // BUGBUG: Can't just forward hresults!
  237. return hresult;
  238. }
  239. // Create a file moniker. Cast to avoid const problem.
  240. IMoniker *pmk;
  241. hresult = CreateFileMoniker((LPOLESTR)lpszFileName, &pmk);
  242. Win4Assert(SUCCEEDED(hresult)
  243. && "CAdvBnd::Load CreateFileMoniker failed");
  244. // Get the running object table
  245. IRunningObjectTable *prot;
  246. hresult = GetRunningObjectTable(0, &prot);
  247. Win4Assert(SUCCEEDED(hresult)
  248. && "CAdvBnd::Load GetRunningObjectTable failed");
  249. // Register in the running object table
  250. IUnknown *punk;
  251. QueryInterface(IID_IUnknown, (void **) &punk);
  252. hresult = prot->Register(0, punk, pmk, &_dwRegister);
  253. Win4Assert(SUCCEEDED(hresult)
  254. && "CAdvBnd::Load Register failed");
  255. // Set filetime to known value
  256. FILETIME filetime;
  257. memset(&filetime, 'B', sizeof(filetime));
  258. // Set time to some known value
  259. prot->NoteChangeTime(_dwRegister, &filetime);
  260. // Release uneeded objects
  261. pmk->Release();
  262. prot->Release();
  263. punk->Release();
  264. return S_OK;
  265. }
  266. //+-------------------------------------------------------------------
  267. //
  268. // Member: CAdvBnd::Save
  269. //
  270. // Synopsis: IPeristFile interface - save
  271. // does little but here for commentry
  272. //
  273. // History: 21-Nov-92 SarahJ Created
  274. //
  275. //--------------------------------------------------------------------
  276. STDMETHODIMP CAdvBnd::Save(LPCOLESTR lpszFileName, BOOL fRemember)
  277. {
  278. Display(TEXT("CAdvBndCF::Save called\n"));
  279. // Forward call to delegated class
  280. IPersistFile *pipfile;
  281. HRESULT hresult = _xiunk->QueryInterface(IID_IPersistFile,
  282. (void **) &pipfile);
  283. hresult = pipfile->Save(lpszFileName, fRemember);
  284. pipfile->Release();
  285. return hresult;
  286. }
  287. //+-------------------------------------------------------------------
  288. //
  289. // Member: CAdvBnd::SaveCpmpleted
  290. // CAdvBnd::GetCurFile
  291. // CAdvBnd::IsDirty
  292. //
  293. // Synopsis: More IPeristFile interface methods
  294. //
  295. // History: 21-Nov-92 SarahJ Created
  296. //
  297. //--------------------------------------------------------------------
  298. STDMETHODIMP CAdvBnd::SaveCompleted(LPCOLESTR lpszFileName)
  299. {
  300. Display(TEXT("CAdvBndCF::SaveCompleted called\n"));
  301. // Forward call to delegated class
  302. IPersistFile *pipfile;
  303. HRESULT hresult = _xiunk->QueryInterface(IID_IPersistFile,
  304. (void **) &pipfile);
  305. hresult = pipfile->SaveCompleted(lpszFileName);
  306. pipfile->Release();
  307. return hresult;
  308. }
  309. STDMETHODIMP CAdvBnd::GetCurFile(LPOLESTR FAR *lpszFileName)
  310. {
  311. Display(TEXT("CAdvBndCF::GetCurFile called\n"));
  312. // Forward call to delegated class
  313. IPersistFile *pipfile;
  314. HRESULT hresult = _xiunk->QueryInterface(IID_IPersistFile,
  315. (void **) &pipfile);
  316. hresult = pipfile->GetCurFile(lpszFileName);
  317. pipfile->Release();
  318. return hresult;
  319. }
  320. STDMETHODIMP CAdvBnd::IsDirty()
  321. {
  322. Display(TEXT("CAdvBndCF::IsDirty called\n"));
  323. // Forward call to delegated class
  324. IPersistFile *pipfile;
  325. HRESULT hresult = _xiunk->QueryInterface(IID_IPersistFile,
  326. (void **) &pipfile);
  327. hresult = pipfile->IsDirty();
  328. pipfile->Release();
  329. return hresult;
  330. }
  331. //+-------------------------------------------------------------------
  332. //
  333. // Interface: IPersist
  334. //
  335. // Synopsis: IPersist interface methods
  336. // Need to return a valid class id here
  337. //
  338. // History: 21-Nov-92 SarahJ Created
  339. //
  340. STDMETHODIMP CAdvBnd::GetClassID(LPCLSID classid)
  341. {
  342. Display(TEXT("CAdvBndCF::GetClassID called\n"));
  343. *classid = CLSID_AdvBnd;
  344. return S_OK;
  345. }