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.

528 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: cdlbsc.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 01-27-97 t-alans (Alan Shi) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <eapp.h>
  18. #include "cdlbsc.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Method: CCodeDLBSC::CCodeDLBSC
  22. //
  23. // Synopsis:
  24. //
  25. // Arguments:
  26. //
  27. //
  28. //
  29. // Returns:
  30. //
  31. // History: 01-27-1997 t-alans (Alan Shi) Created
  32. //
  33. // Notes:
  34. //
  35. //----------------------------------------------------------------------------
  36. CCodeDLBSC::CCodeDLBSC(IOInetProtocolSink *pIOInetProtocolSink,
  37. IOInetBindInfo *pIOInetBindInfo,
  38. CCdlProtocol *pCDLProtocol,
  39. BOOL fGetClassObject)
  40. {
  41. _cRef = 1;
  42. _pIBinding = NULL;
  43. _pOInetProtocolSink = pIOInetProtocolSink;
  44. _fGetClassObject = fGetClassObject;
  45. if (_pOInetProtocolSink != NULL)
  46. {
  47. _pOInetProtocolSink->AddRef();
  48. }
  49. _pIOInetBindInfo = pIOInetBindInfo;
  50. if (_pIOInetBindInfo != NULL)
  51. {
  52. _pIOInetBindInfo->AddRef();
  53. }
  54. _pCDLProtocol = pCDLProtocol;
  55. if (_pCDLProtocol != NULL)
  56. {
  57. _pCDLProtocol->AddRef();
  58. }
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // Method: CCodeDLBSC::~CCodeDLBSC
  63. //
  64. // Synopsis:
  65. //
  66. // Arguments:
  67. //
  68. //
  69. //
  70. // Returns:
  71. //
  72. // History: 01-27-1997 t-alans (Alan Shi) Created
  73. //
  74. // Notes:
  75. //
  76. //----------------------------------------------------------------------------
  77. CCodeDLBSC::~CCodeDLBSC()
  78. {
  79. if (_pOInetProtocolSink != NULL)
  80. {
  81. _pOInetProtocolSink->Release();
  82. }
  83. if (_pIOInetBindInfo != NULL)
  84. {
  85. _pIOInetBindInfo->Release();
  86. }
  87. if (_pCDLProtocol != NULL)
  88. {
  89. _pCDLProtocol->ClearCodeDLBSC();
  90. _pCDLProtocol->Release();
  91. }
  92. }
  93. //+---------------------------------------------------------------------------
  94. //
  95. // Method: CCodeDLBSC::Abort
  96. //
  97. // Synopsis:
  98. //
  99. // Arguments:
  100. //
  101. //
  102. //
  103. // Returns:
  104. //
  105. // History: 01-27-1997 t-alans (Alan Shi) Created
  106. //
  107. // Notes:
  108. //
  109. //----------------------------------------------------------------------------
  110. HRESULT CCodeDLBSC::Abort()
  111. {
  112. if (_pIBinding)
  113. {
  114. return _pIBinding->Abort();
  115. }
  116. else
  117. {
  118. return S_OK;
  119. }
  120. }
  121. /*
  122. *
  123. * IUnknown Methods
  124. *
  125. */
  126. //+---------------------------------------------------------------------------
  127. //
  128. // Method: CCodeDLBSC::QueryInterface
  129. //
  130. // Synopsis:
  131. //
  132. // Arguments:
  133. //
  134. //
  135. //
  136. // Returns:
  137. //
  138. // History: 01-27-1997 t-alans (Alan Shi) Created
  139. //
  140. // Notes:
  141. //
  142. //----------------------------------------------------------------------------
  143. STDMETHODIMP CCodeDLBSC::QueryInterface(REFIID riid, void **ppv)
  144. {
  145. HRESULT hr = E_NOINTERFACE;
  146. *ppv = NULL;
  147. if (riid == IID_IUnknown || riid == IID_IBindStatusCallback)
  148. {
  149. *ppv = (IBindStatusCallback *)this;
  150. }
  151. else if (riid == IID_IServiceProvider)
  152. {
  153. *ppv = (IServiceProvider *)this;
  154. }
  155. if (*ppv != NULL)
  156. {
  157. ((IUnknown *)*ppv)->AddRef();
  158. hr = S_OK;
  159. }
  160. return hr;
  161. }
  162. //+---------------------------------------------------------------------------
  163. //
  164. // Method: CCodeDLBSC::AddRef
  165. //
  166. // Synopsis:
  167. //
  168. // Arguments:
  169. //
  170. //
  171. //
  172. // Returns:
  173. //
  174. // History: 01-27-1997 t-alans (Alan Shi) Created
  175. //
  176. // Notes:
  177. //
  178. //----------------------------------------------------------------------------
  179. STDMETHODIMP_(ULONG) CCodeDLBSC::AddRef()
  180. {
  181. return ++_cRef;
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Method: CCodeDLBSC::Release
  186. //
  187. // Synopsis:
  188. //
  189. // Arguments:
  190. //
  191. //
  192. //
  193. // Returns:
  194. //
  195. // History: 01-27-1997 t-alans (Alan Shi) Created
  196. //
  197. // Notes:
  198. //
  199. //----------------------------------------------------------------------------
  200. STDMETHODIMP_(ULONG) CCodeDLBSC::Release()
  201. {
  202. if (--_cRef)
  203. {
  204. return _cRef;
  205. }
  206. delete this;
  207. return 0;
  208. }
  209. /*
  210. *
  211. * IBindStatusCallback Methods
  212. *
  213. */
  214. //+---------------------------------------------------------------------------
  215. //
  216. // Method: CCodeDLBSC::OnStartBinding
  217. //
  218. // Synopsis:
  219. //
  220. // Arguments:
  221. //
  222. //
  223. //
  224. // Returns:
  225. //
  226. // History: 01-27-1997 t-alans (Alan Shi) Created
  227. //
  228. // Notes:
  229. //
  230. //----------------------------------------------------------------------------
  231. STDMETHODIMP CCodeDLBSC::OnStartBinding(DWORD grfBSCOption, IBinding *pib)
  232. {
  233. if (_pIBinding != NULL)
  234. {
  235. _pIBinding->Release();
  236. }
  237. _pIBinding = pib;
  238. if (_pIBinding != NULL)
  239. {
  240. _pIBinding->AddRef();
  241. }
  242. return S_OK;
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // Method: CCodeDLBSC::OnStopBinding
  247. //
  248. // Synopsis:
  249. //
  250. // Arguments:
  251. //
  252. //
  253. //
  254. // Returns:
  255. //
  256. // History: 01-27-1997 t-alans (Alan Shi) Created
  257. //
  258. // Notes:
  259. //
  260. //----------------------------------------------------------------------------
  261. STDMETHODIMP CCodeDLBSC::OnStopBinding(HRESULT hresult, LPCWSTR szError)
  262. {
  263. HRESULT hr = S_OK;
  264. DWORD dwError = 0;
  265. DWORD grfBINDF = 0;
  266. BINDINFO bindinfo;
  267. _pCDLProtocol->SetDataPending(FALSE);
  268. if (SUCCEEDED(hresult))
  269. {
  270. if (_fGetClassObject)
  271. {
  272. EProtAssert(_pUnk);
  273. // put _pUnk into the bind context for CBinding to retrieve
  274. hresult = _pCDLProtocol->RegisterIUnknown(_pUnk);
  275. // no need for _pUnk anymore, release it
  276. _pUnk->Release();
  277. _pUnk = NULL;
  278. if (SUCCEEDED(hresult))
  279. {
  280. _pOInetProtocolSink->ReportProgress(BINDSTATUS_IUNKNOWNAVAILABLE,
  281. NULL);
  282. }
  283. }
  284. else
  285. {
  286. if (!IsEqualGUID(_pCDLProtocol->GetClsid() , CLSID_NULL))
  287. {
  288. LPOLESTR pwzStrClsId;
  289. StringFromCLSID(_pCDLProtocol->GetClsid(), &pwzStrClsId);
  290. _pOInetProtocolSink->ReportProgress(BINDSTATUS_CLSIDCANINSTANTIATE, pwzStrClsId);
  291. delete [] pwzStrClsId;
  292. }
  293. }
  294. }
  295. hr = _pOInetProtocolSink->ReportResult(hresult, dwError, szError);
  296. return hr;
  297. }
  298. //+---------------------------------------------------------------------------
  299. //
  300. // Method: CCodeDLBSC::OnObjectAvailable
  301. //
  302. // Synopsis:
  303. //
  304. // Arguments:
  305. //
  306. //
  307. //
  308. // Returns:
  309. //
  310. // History: 01-27-1997 t-alans (Alan Shi) Created
  311. //
  312. // Notes:
  313. //
  314. //----------------------------------------------------------------------------
  315. STDMETHODIMP CCodeDLBSC::OnObjectAvailable(REFIID riid, IUnknown *punk)
  316. {
  317. EProtAssert(!_pUnk && punk);
  318. _pUnk = punk;
  319. _pUnk->AddRef();
  320. return S_OK;
  321. }
  322. //+---------------------------------------------------------------------------
  323. //
  324. // Method: CCodeDLBSC::GetPriority
  325. //
  326. // Synopsis:
  327. //
  328. // Arguments:
  329. //
  330. //
  331. //
  332. // Returns:
  333. //
  334. // History: 01-27-1997 t-alans (Alan Shi) Created
  335. //
  336. // Notes:
  337. //
  338. //----------------------------------------------------------------------------
  339. STDMETHODIMP CCodeDLBSC::GetPriority(LONG *pnPriority)
  340. {
  341. return S_OK;
  342. }
  343. //+---------------------------------------------------------------------------
  344. //
  345. // Method: CCodeDLBSC::OnLowResource
  346. //
  347. // Synopsis:
  348. //
  349. // Arguments:
  350. //
  351. //
  352. //
  353. // Returns:
  354. //
  355. // History: 01-27-1997 t-alans (Alan Shi) Created
  356. //
  357. // Notes:
  358. //
  359. //----------------------------------------------------------------------------
  360. STDMETHODIMP CCodeDLBSC::OnLowResource(DWORD dwReserved)
  361. {
  362. return S_OK;
  363. }
  364. //+---------------------------------------------------------------------------
  365. //
  366. // Method: CCodeDLBSC::OnProgress
  367. //
  368. // Synopsis:
  369. //
  370. // Arguments:
  371. //
  372. //
  373. //
  374. // Returns:
  375. //
  376. // History: 01-27-1997 t-alans (Alan Shi) Created
  377. //
  378. // Notes:
  379. //
  380. //----------------------------------------------------------------------------
  381. STDMETHODIMP CCodeDLBSC::OnProgress(ULONG ulProgress, ULONG ulProgressMax,
  382. ULONG ulStatusCode,
  383. LPCWSTR szStatusText)
  384. {
  385. EProtAssert(_pOInetProtocolSink != NULL);
  386. return _pOInetProtocolSink->ReportProgress(ulStatusCode, szStatusText);
  387. }
  388. //+---------------------------------------------------------------------------
  389. //
  390. // Method: CCodeDLBSC::GetBindInfo
  391. //
  392. // Synopsis:
  393. //
  394. // Arguments:
  395. //
  396. //
  397. //
  398. // Returns:
  399. //
  400. // History: 01-27-1997 t-alans (Alan Shi) Created
  401. //
  402. // Notes:
  403. //
  404. //----------------------------------------------------------------------------
  405. STDMETHODIMP CCodeDLBSC::GetBindInfo(DWORD *pgrfBINDF, BINDINFO *pbindInfo)
  406. {
  407. EProtAssert(_pIOInetBindInfo != NULL);
  408. return _pIOInetBindInfo->GetBindInfo(pgrfBINDF, pbindInfo);
  409. }
  410. //+---------------------------------------------------------------------------
  411. //
  412. // Method: CCodeDLBSC::OnDataAvailable
  413. //
  414. // Synopsis:
  415. //
  416. // Arguments:
  417. //
  418. //
  419. //
  420. // Returns:
  421. //
  422. // History: 01-27-1997 t-alans (Alan Shi) Created
  423. //
  424. // Notes:
  425. //
  426. //----------------------------------------------------------------------------
  427. STDMETHODIMP CCodeDLBSC::OnDataAvailable(DWORD grfBSCF, DWORD dwSize,
  428. FORMATETC *pformatetc,
  429. STGMEDIUM *pstgmed)
  430. {
  431. return S_OK;
  432. }
  433. /*
  434. *
  435. * IWindowForBindingUI Methods
  436. *
  437. */
  438. //+---------------------------------------------------------------------------
  439. //
  440. // Method: CCodeDLBSC::QueryService
  441. //
  442. // Synopsis:
  443. //
  444. // Arguments:
  445. //
  446. //
  447. //
  448. // Returns:
  449. //
  450. // History: 01-27-1997 t-alans (Alan Shi) Created
  451. //
  452. // Notes:
  453. //
  454. //----------------------------------------------------------------------------
  455. STDMETHODIMP CCodeDLBSC::QueryService(REFGUID rsid, REFIID riid, void ** ppvObj)
  456. {
  457. HRESULT hr = NOERROR;
  458. IServiceProvider *pIServiceProvider = NULL;
  459. EProtAssert(ppvObj);
  460. if (!ppvObj)
  461. return E_INVALIDARG;
  462. *ppvObj = 0;
  463. hr = _pOInetProtocolSink->QueryInterface(IID_IServiceProvider,
  464. (LPVOID *)&pIServiceProvider);
  465. if (SUCCEEDED(hr))
  466. {
  467. hr = pIServiceProvider->QueryService(rsid, riid, (LPVOID *)ppvObj);
  468. pIServiceProvider->Release();
  469. }
  470. return hr;
  471. }