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.

153 lines
3.5 KiB

  1. #ifndef _STRUTIL_H_
  2. #define _STRUTIL_H_
  3. #include <stock.h>
  4. #include <wincrypt.h>
  5. INLINE BOOL
  6. IsEmptyStringA(LPCSTR pcsz)
  7. {
  8. return (NULL == pcsz) || ('\0' == *pcsz);
  9. }
  10. INLINE BOOL
  11. IsEmptyStringW(LPCWSTR pcwsz)
  12. {
  13. return (NULL == pcwsz) || (L'\0' == *pcwsz);
  14. }
  15. #if defined(UNICODE)
  16. #define IsEmptyString IsEmptyStringW
  17. #else // defined(UNICODE)
  18. #define IsEmptyString IsEmptyStringA
  19. #endif // defined(UNICODE)
  20. #define IS_EMPTY_STRING(s) (IsEmptyString(s))
  21. #define FEmptySz(psz) (IsEmptyString(psz))
  22. #define SetEmptySz(psz) (*(psz) = _T('\0'))
  23. // global helper functions for Unicode support in a DBCS environment
  24. int UnicodeCompare(PCWSTR s, PCWSTR t);
  25. PWSTR NewUnicodeString(PCWSTR wszText);
  26. BOOL UnicodeIsNumber(PCWSTR wszText);
  27. PWSTR DBCSToUnicode(UINT uCodePage, PCSTR szText);
  28. PSTR UnicodeToDBCS(UINT uCodePage, PCWSTR wszText);
  29. INLINE PWSTR AnsiToUnicode(PCSTR szText)
  30. {
  31. return DBCSToUnicode(CP_ACP, szText);
  32. }
  33. INLINE PWSTR OEMToUnicode(PCSTR szText)
  34. {
  35. return DBCSToUnicode(CP_OEMCP, szText);
  36. }
  37. INLINE PSTR UnicodeToAnsi(PCWSTR wszText)
  38. {
  39. return UnicodeToDBCS(CP_ACP, wszText);
  40. }
  41. INLINE PSTR UnicodeToOEM(PCWSTR wszText)
  42. {
  43. return UnicodeToDBCS(CP_OEMCP, wszText);
  44. }
  45. // Functions to convert between Quad Words (expressed as ULARGE_INTEGERs)
  46. // and ANSI strings.
  47. BOOL HexStringToQWordA(LPCSTR pcszString, ULARGE_INTEGER* pqw);
  48. int QWordToHexStringA(ULARGE_INTEGER qw, LPSTR pszString);
  49. // Function to convert from a hex string to a DWORD.
  50. DWORD DwFromHex(LPCTSTR pchHex);
  51. // CCHMAX_HEX_ULARGE_INTEGER - defines the minimum string buffer size needed
  52. // for the second parameter of QWordToHexStringA().
  53. #define CCHMAX_HEX_ULARGE_INTEGER 17 // 16 characters + n.t.
  54. #define CCH_HEX_DWORD 8
  55. #define CCH_HEX_QWORD 16
  56. #define BITS_PER_HEX_CHAR 4
  57. // Other Random string functions
  58. VOID GuidToSz(GUID * pguid, LPTSTR lpchDest);
  59. /* sizeof(GUID)*2 + 7 (includes NULL terminator) characters (see GuidToSz) */
  60. #define LENGTH_SZGUID_FORMATTED 39
  61. int WINAPI RtStrToInt(LPCTSTR lpSrc); // atoi()
  62. #define ATOI RtStrToInt
  63. #ifdef __cplusplus
  64. extern "C"{
  65. #endif
  66. UINT DecimalStringToUINT(LPCTSTR pcszString);
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #ifdef __cplusplus
  71. extern "C"{
  72. #endif
  73. LPCTSTR _StrChr(LPCTSTR psz, TCHAR c);
  74. int _StrCmpN(LPCTSTR psz1, LPCTSTR psz2, UINT maxChars);
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. LPCTSTR _StrStr(LPCTSTR pcsz1, LPCTSTR pcsz2);
  79. LPCWSTR _StrStrW(LPCWSTR pcsz1, LPCWSTR pcsz2);
  80. LPSTR _StrPbrkA(LPCSTR pcszString, LPCSTR pcszSearch);
  81. LPWSTR _StrPbrkW(LPCWSTR pcszString, LPCWSTR pcszSearch);
  82. #if defined(UNICODE)
  83. #define _StrPbrk _StrPbrkW
  84. #else // defined(UNICODE)
  85. #define _StrPbrk _StrPbrkA
  86. #endif // defined(UNICODE)
  87. LPTSTR SzFindLastCh(LPTSTR lpsz, TCHAR ch);
  88. UINT TrimSz(PTCHAR psz);
  89. // Local LStrLenW function is unnecessary, since Windows 95 supports
  90. // lstrlenW natively
  91. #define LStrLenW lstrlenW
  92. // Map LStrCpyW to its Win32 equivalent for Unicode builds
  93. #if defined UNICODE
  94. #define LStrCpyW lstrcpyW
  95. #define LStrCpyNW lstrcpyn
  96. #else // defined UNICODE
  97. LPWSTR LStrCpyW(LPWSTR pszDest, LPWSTR pszSrc);
  98. LPWSTR LStrCpyNW(LPWSTR pszDest, LPCWSTR pszSrc, INT iMaxLength);
  99. #endif // defined UNICODE
  100. LPWSTR _StrLwrW(LPWSTR pwszSrc);
  101. #ifdef __cplusplus
  102. class CHash
  103. {
  104. public:
  105. CHash();
  106. ~CHash();
  107. DWORD GetHashedData(PBYTE pbData, DWORD cbData, void ** ppvHashedData);
  108. private:
  109. HCRYPTPROV m_hProv;
  110. HCRYPTHASH m_hHash;
  111. PBYTE m_pbHashedData;
  112. DWORD m_cbHashedData;
  113. BOOL m_fReady;
  114. };
  115. #endif
  116. DWORD HashPasswd(PBYTE pbPasswd, DWORD cbPasswd, void **ppvData);
  117. #endif // ndef STRUTIL_H