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.

154 lines
2.7 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cprovcf.cxx
  7. //
  8. // Contents: Windows NT 3.5 Provider Object Class Factory Code
  9. //
  10. // CWinNTProviderCF::CreateInstance
  11. //
  12. // History: 01-30-95 krishnag Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. // Class CWinNTProvider
  18. CWinNTProvider::CWinNTProvider()
  19. {
  20. }
  21. HRESULT
  22. CWinNTProvider::Create(
  23. CWinNTProvider FAR * FAR * ppProvider
  24. )
  25. {
  26. CWinNTProvider FAR * pProvider = NULL;
  27. HRESULT hr = S_OK;
  28. //Create the Provider Object
  29. pProvider = new CWinNTProvider();
  30. if (pProvider == NULL) {
  31. RRETURN(ResultFromScode(E_OUTOFMEMORY));
  32. }
  33. if (FAILED(hr)) {
  34. delete pProvider;
  35. RRETURN(hr);
  36. }
  37. *ppProvider = pProvider;
  38. RRETURN_EXP_IF_ERR(hr);
  39. }
  40. CWinNTProvider::~CWinNTProvider( )
  41. {
  42. ENLIST_TRACKING(CWinNTProvider);
  43. }
  44. STDMETHODIMP
  45. CWinNTProvider::QueryInterface(
  46. REFIID iid,
  47. LPVOID FAR* ppv
  48. )
  49. {
  50. if (ppv == NULL) {
  51. RRETURN(E_POINTER);
  52. }
  53. if (IsEqualIID(iid, IID_IUnknown))
  54. {
  55. *ppv = this;
  56. }
  57. else if (IsEqualIID(iid, IID_IParseDisplayName))
  58. {
  59. *ppv = (IADs FAR *) this;
  60. }
  61. else
  62. {
  63. *ppv = NULL;
  64. return E_NOINTERFACE;
  65. }
  66. AddRef();
  67. return NOERROR;
  68. }
  69. STDMETHODIMP
  70. CWinNTProvider::ParseDisplayName(
  71. IBindCtx* pbc,
  72. WCHAR* szDisplayName,
  73. ULONG* pchEaten,
  74. IMoniker** ppmk
  75. )
  76. {
  77. HRESULT hr;
  78. *ppmk = NULL;
  79. if (pchEaten != NULL){
  80. *pchEaten = 0;
  81. }
  82. hr = ResolvePathName(
  83. pbc,
  84. szDisplayName,
  85. pchEaten,
  86. ppmk
  87. );
  88. RRETURN_EXP_IF_ERR(hr);
  89. }
  90. HRESULT
  91. CWinNTProvider::ResolvePathName(
  92. IBindCtx* pbc,
  93. WCHAR* szDisplayName,
  94. ULONG* pchEaten,
  95. IMoniker** ppmk
  96. )
  97. {
  98. HRESULT hr;
  99. LPUNKNOWN pUnknown = NULL;
  100. //
  101. // In try block because the Credentials do an InitCritSect
  102. // down the line on a static variable. This call can fail
  103. // so we need to catch it.
  104. //
  105. if (!pchEaten) {
  106. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  107. }
  108. __try {
  109. CWinNTCredentials Credentials;
  110. *pchEaten = 0;
  111. hr = GetObject(szDisplayName, (LPVOID *)&pUnknown, Credentials);
  112. BAIL_ON_FAILURE(hr)
  113. hr = CreatePointerMoniker(pUnknown, ppmk);
  114. BAIL_ON_FAILURE(hr);
  115. *pchEaten += wcslen(szDisplayName);
  116. }
  117. __except (EXCEPTION_EXECUTE_HANDLER) {
  118. RRETURN(E_FAIL);
  119. }
  120. error :
  121. if (pUnknown) {
  122. pUnknown->Release();
  123. }
  124. RRETURN(hr);
  125. }