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.

252 lines
4.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: util.hxx
  7. //
  8. // Contents: Prototypes for miscellaneous utility functions.
  9. //
  10. // History: 09-18-1997 DavidMun Created
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef __UTIL_HXX_
  14. #define __UTIL_HXX_
  15. HRESULT
  16. LoadStr(
  17. ULONG ids,
  18. PWSTR wszBuf,
  19. ULONG cchBuf,
  20. PCWSTR wszDefault = NULL);
  21. void
  22. NewDupStr(
  23. PWSTR *ppwzDup,
  24. PCWSTR wszSrc);
  25. HRESULT
  26. CoTaskDupStr(
  27. PWSTR *ppwzDup,
  28. PCWSTR wzSrc);
  29. HRESULT
  30. UnicodeToAnsi(
  31. LPSTR szTo,
  32. LPCWSTR pwszFrom,
  33. ULONG cbTo);
  34. void
  35. UnicodeStringToWsz(
  36. const UNICODE_STRING &refustr,
  37. PWSTR wszBuf,
  38. ULONG cchBuf);
  39. void
  40. StripLeadTrailSpace(
  41. PWSTR ptsz);
  42. void
  43. InvokeWinHelp(
  44. UINT message,
  45. WPARAM wParam,
  46. LPARAM lParam,
  47. PCWSTR wszHelpFileName,
  48. ULONG aulControlIdToHelpIdMap[]);
  49. HRESULT
  50. AllocateQueryInfo(
  51. PDSQUERYINFO *ppdsqi);
  52. void
  53. FreeQueryInfo(
  54. PDSQUERYINFO pqi);
  55. void
  56. MessageWait(
  57. ULONG cObjects,
  58. const HANDLE *aObjects,
  59. ULONG ulTimeout);
  60. void
  61. GetPolicySettings(
  62. ULONG *pcMaxHits,
  63. BOOL *pfExcludeDisabled);
  64. //+--------------------------------------------------------------------------
  65. //
  66. // Function: IsCredError
  67. //
  68. // Synopsis: Return TRUE if [hr] is a credential-related error.
  69. //
  70. // History: 04-30-1998 DavidMun Created
  71. //
  72. //---------------------------------------------------------------------------
  73. inline BOOL
  74. IsCredError(
  75. HRESULT hr)
  76. {
  77. BOOL fIsCredError;
  78. switch (hr)
  79. {
  80. case HRESULT_FROM_WIN32(ERROR_INVALID_PASSWORD):
  81. case HRESULT_FROM_WIN32(ERROR_PASSWORD_EXPIRED):
  82. case HRESULT_FROM_WIN32(ERROR_LOGON_FAILURE):
  83. case HRESULT_FROM_WIN32(ERROR_BAD_USERNAME):
  84. case HRESULT_FROM_WIN32(ERROR_ACCOUNT_DISABLED):
  85. case HRESULT_FROM_WIN32(ERROR_ACCOUNT_LOCKED_OUT):
  86. case HRESULT_FROM_WIN32(ERROR_SESSION_CREDENTIAL_CONFLICT):
  87. case E_ACCESSDENIED:
  88. fIsCredError = TRUE;
  89. break;
  90. default:
  91. fIsCredError = FALSE;
  92. break;
  93. }
  94. return fIsCredError;
  95. }
  96. inline LONG
  97. WindowRectWidth(
  98. const RECT &rc)
  99. {
  100. return rc.right - rc.left;
  101. }
  102. inline LONG
  103. WindowRectHeight(
  104. const RECT &rc)
  105. {
  106. return rc.bottom - rc.top;
  107. }
  108. PWSTR
  109. wcsistr(
  110. PCWSTR pwzSearchIn,
  111. PCWSTR pwzSearchFor);
  112. HRESULT
  113. ProviderFlagFromPath(
  114. const String &strADsPath,
  115. ULONG *pulProvider);
  116. BOOL
  117. IsDisabled(
  118. IADs *pADs);
  119. BOOL
  120. IsLocalComputername(
  121. PCWSTR pwzComputerName);
  122. BOOL
  123. IsCurrentUserLocalUser();
  124. inline BOOL
  125. IsDownlevelFlagSet(ULONG flLeft, ULONG flRight)
  126. {
  127. return ((flLeft & flRight) & ~DOWNLEVEL_FILTER_BIT);
  128. }
  129. void
  130. DisableSystemMenuClose(
  131. HWND hwnd);
  132. HRESULT
  133. AddStringToCombo(
  134. HWND hwndCombo,
  135. ULONG ids);
  136. void
  137. LdapEscape(
  138. String *pstrEscaped);
  139. void
  140. UpdateLookForInText(
  141. HWND hwndDlg,
  142. const CObjectPicker &rop);
  143. typedef BOOL (*PFNOBJECTTEST)(const DS_SELECTION &, LPARAM);
  144. void
  145. AddFromDataObject(
  146. ULONG idScope,
  147. IDataObject *pdo,
  148. PFNOBJECTTEST pfnTestObject,
  149. LPARAM lParam,
  150. CDsObjectList *pdsol);
  151. String
  152. UliToStr(
  153. const ULARGE_INTEGER &uli);
  154. void
  155. SetDefaultColumns(
  156. HWND hwnd,
  157. const CObjectPicker &rop,
  158. AttrKeyVector *pvakListviewColumns);
  159. //>>
  160. String
  161. GetClassName(const CObjectPicker &rop);
  162. template<class container_class, class value_class>
  163. BOOL
  164. AddIfNotPresent(
  165. container_class *pContainer,
  166. value_class Value)
  167. {
  168. if (pContainer->end() == find(pContainer->begin(),
  169. pContainer->end(),
  170. Value))
  171. {
  172. pContainer->push_back(Value);
  173. return TRUE;
  174. }
  175. return FALSE;
  176. }
  177. inline void
  178. SetListViewSelection(
  179. HWND hwndLV,
  180. int iItem)
  181. {
  182. ListView_SetItemState(hwndLV,
  183. iItem,
  184. LVIS_FOCUSED | LVIS_SELECTED,
  185. LVIS_FOCUSED | LVIS_SELECTED);
  186. }
  187. HRESULT
  188. LocalAllocString(LPTSTR* ppResult,
  189. LPCTSTR pString);
  190. HRESULT
  191. IsSidGood( IN LPCWSTR pszTargetMachineName,
  192. IN LPCWSTR pszAccountName,
  193. IN PSID pInputSid,
  194. OUT PBOOL pbGood);
  195. class ProgressDialog{
  196. public:
  197. ProgressDialog(HWND hwnd):m_hwndPopupOwner(hwnd),
  198. m_pProgressDlg(NULL){}
  199. void CreateProgressDialog(void);
  200. void CloseProgressDialog(void);
  201. HRESULT SetProgress(ULONG uCount);
  202. private:
  203. IProgressDialog *m_pProgressDlg;
  204. HWND m_hwndPopupOwner;
  205. };
  206. #endif // __UTIL_HXX_