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.

220 lines
4.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: getobj.cxx
  7. //
  8. // Contents: ADs Wrapper Function to mimic Visual Basic's GetObject
  9. //
  10. //
  11. // History: 11-15-95 krishnag Created.
  12. // 07-12-96 t-danal Added path validation.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "oleds.hxx"
  16. #pragma hdrstop
  17. extern PROUTER_ENTRY g_pRouterHead;
  18. extern CRITICAL_SECTION g_csRouterHeadCritSect;
  19. BOOL
  20. IsPathOfProgId(
  21. LPWSTR ProgId,
  22. LPWSTR Path
  23. );
  24. BOOL
  25. IsADsProgId(
  26. LPWSTR Path
  27. );
  28. //+---------------------------------------------------------------------------
  29. // Function: ADsGetObject
  30. //
  31. // Synopsis:
  32. //
  33. // Arguments: [LPWSTR lpszPathName]
  34. // [REFIID riid]
  35. // [void FAR * FAR * ppObject]
  36. //
  37. // Returns: HRESULT
  38. //
  39. // Modifies: -
  40. //
  41. // History: 07-12-95 t-danal Created.
  42. //
  43. //----------------------------------------------------------------------------
  44. HRESULT
  45. ADsGetObject(
  46. LPCWSTR lpszPathName,
  47. REFIID riid,
  48. void FAR * FAR * ppObject
  49. )
  50. {
  51. HRESULT hr;
  52. hr = GetObject((LPWSTR)lpszPathName,
  53. riid,
  54. ppObject,
  55. FALSE);
  56. RRETURN(hr);
  57. }
  58. //+---------------------------------------------------------------------------
  59. // Function: GetObject
  60. //
  61. // Synopsis:
  62. //
  63. // Arguments: [LPWSTR lpszPathName]
  64. // [REFIID riid]
  65. // [void FAR * FAR * ppObject]
  66. // [BOOL Generic]
  67. //
  68. // Returns: HRESULT
  69. //
  70. // Modifies: -
  71. //
  72. // History: 11-03-95 krishnag Created.
  73. // 07-12-95 t-danal Added router verification and
  74. // renamed from ADsGetObject
  75. //
  76. //----------------------------------------------------------------------------
  77. HRESULT
  78. GetObject(
  79. LPWSTR lpszPathName,
  80. REFIID riid,
  81. void FAR * FAR * ppObject,
  82. BOOL bRelative
  83. )
  84. {
  85. HRESULT hr;
  86. ULONG chEaten = 0L;
  87. IMoniker * pMoniker = NULL;
  88. IBindCtx *pbc = NULL;
  89. //
  90. // Make sure the router has been initialized
  91. //
  92. EnterCriticalSection(&g_csRouterHeadCritSect);
  93. if (!g_pRouterHead) {
  94. g_pRouterHead = InitializeRouter();
  95. }
  96. LeaveCriticalSection(&g_csRouterHeadCritSect);
  97. PROUTER_ENTRY lpRouter = g_pRouterHead;
  98. if (bRelative || !IsADsProgId(lpszPathName)) {
  99. //
  100. // Check if the Path matches with ProviderProgId or the Aliases
  101. //
  102. while (lpRouter &&
  103. (!IsPathOfProgId(lpRouter->szProviderProgId, lpszPathName) &&
  104. !IsPathOfProgId(lpRouter->szAliases, lpszPathName)))
  105. lpRouter = lpRouter->pNext;
  106. if (!lpRouter)
  107. RRETURN(E_FAIL);
  108. }
  109. hr = CreateBindCtx(0, &pbc);
  110. BAIL_IF_ERROR(hr);
  111. hr = MkParseDisplayName(pbc,
  112. lpszPathName,
  113. &chEaten,
  114. &pMoniker);
  115. BAIL_IF_ERROR(hr);
  116. hr = pMoniker->BindToObject(pbc, NULL, riid, ppObject);
  117. BAIL_IF_ERROR(hr);
  118. cleanup:
  119. if (pbc) {
  120. pbc->Release();
  121. }
  122. if (pMoniker) {
  123. pMoniker->Release();
  124. }
  125. RRETURN(hr);
  126. }
  127. //+---------------------------------------------------------------------------
  128. // Function: IsPathOfProgId
  129. //
  130. // Synopsis: Checks if an OLE Path corresponds to given ProgId.
  131. // Path must be @Foo! or Foo: style.
  132. //
  133. // Arguments: [LPWSTR ProgId]
  134. // [LPWSTR Path]
  135. //
  136. // Returns: BOOL
  137. //
  138. // Modifies: -
  139. //
  140. // History: 07-12-95 t-danal Created
  141. //
  142. //----------------------------------------------------------------------------
  143. BOOL
  144. IsPathOfProgId(
  145. LPWSTR ProgId,
  146. LPWSTR Path
  147. )
  148. {
  149. if (!ProgId || !Path) // Just in case...
  150. return FALSE;
  151. if (*Path == L'@')
  152. Path++;
  153. if(wcsncmp(ProgId, Path, wcslen(ProgId)))
  154. return FALSE;
  155. return TRUE;
  156. }
  157. //+---------------------------------------------------------------------------
  158. // Function: IsADsProgId
  159. //
  160. // Synopsis: Checks if the ProgIds of paths is ADs progid.
  161. // Paths must be @Foo! or Foo: style.
  162. //
  163. // Arguments: [LPWSTR Path]
  164. //
  165. // Returns: BOOL
  166. //
  167. // Modifies: -
  168. //
  169. // History: 07-12-95 t-danal Created
  170. //
  171. //----------------------------------------------------------------------------
  172. BOOL
  173. IsADsProgId(
  174. LPWSTR Path
  175. )
  176. {
  177. int cch = 0;
  178. LPWSTR pEnd;
  179. if (!Path)
  180. return FALSE;
  181. if (*Path == L'@')
  182. Path++;
  183. pEnd = Path;
  184. while (*pEnd &&
  185. *pEnd != L'!' &&
  186. *pEnd != L':') {
  187. pEnd++;
  188. }
  189. if (_wcsnicmp(L"ADS", Path, (int)(pEnd-Path)))
  190. return FALSE;
  191. return TRUE;
  192. }