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.

233 lines
5.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. ClbMisc
  5. Abstract:
  6. This header file describes the miscellaneous services of the Calais Library.
  7. Author:
  8. Doug Barlow (dbarlow) 7/16/1996
  9. Environment:
  10. Win32, C++ w/ Exceptions
  11. Notes:
  12. --*/
  13. #ifndef _CLBMISC_H_
  14. #define _CLBMISC_H_
  15. #include <stdio.h>
  16. #include <tchar.h>
  17. //
  18. // Miscellaneous definitions.
  19. //
  20. extern int
  21. MemCompare( // Non CRTL memory compare routine.
  22. IN LPCBYTE pbOne,
  23. IN LPCBYTE pbTwo,
  24. IN DWORD cbLength);
  25. extern DWORD
  26. MStrAdd( // Add an ANSI string to a multistring.
  27. IN OUT CBuffer &bfMsz,
  28. IN LPCSTR szAdd);
  29. extern DWORD
  30. MStrAdd( // Add a wide string to a multistring.
  31. IN OUT CBuffer &bfMsz,
  32. IN LPCWSTR szAdd);
  33. extern DWORD
  34. MStrLen( // Return the length of an ANSI Multistring, in chars.
  35. LPCSTR mszString);
  36. extern DWORD
  37. MStrLen( // Return the length of a wide Multistring, in chars.
  38. LPCWSTR mszString);
  39. extern LPCTSTR
  40. FirstString( // Return first string segment in a multistring.
  41. IN LPCTSTR szMultiString);
  42. extern LPCTSTR
  43. NextString( // Return next string segment in a multistring.
  44. IN LPCTSTR szMultiString);
  45. extern LPCTSTR
  46. StringIndex( // Return n'th string segment in a multistring.
  47. IN LPCTSTR szMultiString,
  48. IN DWORD dwIndex);
  49. extern DWORD
  50. MStringCount(
  51. LPCTSTR mszInString); // count strings in multistring
  52. extern DWORD
  53. MStringSort( // Sort multistring, removing duplicates.
  54. LPCTSTR mszInString,
  55. CBuffer &bfOutString);
  56. extern DWORD
  57. MStringMerge( // Merge two multistrings, eliminating duplicates.
  58. LPCTSTR mszOne,
  59. LPCTSTR mszTwo,
  60. CBuffer &bfOutString);
  61. extern DWORD
  62. MStringCommon( // Get the intersection of two multistrings.
  63. LPCTSTR mszOne,
  64. LPCTSTR mszTwo,
  65. CBuffer &bfOutString);
  66. extern DWORD
  67. MStringRemove( // Remove 2nd string entries from 1st string.
  68. LPCTSTR mszOne,
  69. LPCTSTR mszTwo,
  70. CBuffer &bfOutString);
  71. extern BOOL
  72. ParseAtr( // Parse a smartcard ATR string.
  73. LPCBYTE pbAtr,
  74. LPDWORD pdwAtrLen = NULL,
  75. LPDWORD pdwHistOffset = NULL,
  76. LPDWORD pcbHistory = NULL,
  77. DWORD cbMaxLen = 33);
  78. extern BOOL
  79. AtrCompare( // Compare an ATR to an ATR/Mask pair.
  80. LPCBYTE pbAtr1,
  81. LPCBYTE pbAtr2,
  82. LPCBYTE pbMask, // = NULL
  83. DWORD cbAtr2); // = 0
  84. extern DWORD
  85. MoveString( // Move an ANSI string into a buffer, converting to
  86. CBuffer &bfDst, // TCHARs.
  87. LPCSTR szSrc,
  88. DWORD dwLength = (DWORD)(-1));
  89. extern DWORD
  90. MoveString( // Move a UNICODE string into a buffer, converting to
  91. CBuffer &bfDst, // TCHARs.
  92. LPCWSTR szSrc,
  93. DWORD dwLength = (DWORD)(-1));
  94. extern DWORD
  95. MoveToAnsiString( // Move a string into a UNICODE buffer, converting from
  96. LPSTR szDst, // TCHARs.
  97. LPCTSTR szSrc,
  98. DWORD cchLength);
  99. extern DWORD
  100. MoveToUnicodeString( // Move a string into an ANSI buffer, converting from
  101. LPWSTR szDst, // TCHARs.
  102. LPCTSTR szSrc,
  103. DWORD cchLength);
  104. extern DWORD
  105. MoveToAnsiMultiString( // Move a multistring into an ANSI buffer, converting
  106. LPSTR mszDst, // from TCHARs.
  107. LPCTSTR mszSrc,
  108. DWORD cchLength);
  109. extern DWORD
  110. MoveToUnicodeMultiString( // Move a multistring into a UNICODE buffer,
  111. LPWSTR mszDst, // converting from TCHARs.
  112. LPCTSTR mszSrc,
  113. DWORD cchLength);
  114. extern LPCTSTR
  115. ErrorString( // Convert an error code into a string.
  116. DWORD dwErrorCode);
  117. extern void
  118. FreeErrorString( // Free the string returned from ErrorString.
  119. LPCTSTR szErrorString);
  120. extern DWORD
  121. SelectString( // Index a given string against a list of possible
  122. LPCTSTR szSource, // strings. Last parameter is NULL.
  123. ...);
  124. extern void
  125. StringFromGuid(
  126. IN LPCGUID pguidResult, // GUID to convert to text
  127. OUT LPTSTR szGuid); // 39+ character buffer to receive GUID as text.
  128. //
  129. //==============================================================================
  130. //
  131. // CErrorString
  132. //
  133. // A trivial class to simplify the use of the ErrorString service.
  134. //
  135. class CErrorString
  136. {
  137. public:
  138. // Constructors & Destructor
  139. CErrorString(DWORD dwError = 0)
  140. {
  141. m_szErrorString = NULL;
  142. SetError(dwError);
  143. };
  144. ~CErrorString()
  145. {
  146. if (m_szErrorString != m_szHexError)
  147. FreeErrorString(m_szErrorString);
  148. };
  149. // Properties
  150. // Methods
  151. void SetError(DWORD dwError)
  152. {
  153. m_dwError = dwError;
  154. };
  155. LPCTSTR Value(void)
  156. {
  157. LPCTSTR szErr = NULL;
  158. if (m_szErrorString != m_szHexError)
  159. FreeErrorString(m_szErrorString);
  160. try {
  161. szErr = ErrorString(m_dwError);
  162. } catch (...) {}
  163. if (NULL == szErr)
  164. {
  165. _stprintf(m_szHexError, _T("0x%08x"), m_dwError);
  166. m_szErrorString = m_szHexError;
  167. }
  168. else
  169. m_szErrorString = szErr;
  170. return m_szErrorString;
  171. };
  172. // Operators
  173. operator LPCTSTR(void)
  174. {
  175. return Value();
  176. };
  177. protected:
  178. // Properties
  179. DWORD m_dwError;
  180. LPCTSTR m_szErrorString;
  181. TCHAR m_szHexError[11]; // Big enough to hold 0x%08x\0
  182. // Methods
  183. };
  184. #endif // _CLBMISC_H_