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.

141 lines
4.9 KiB

  1. //
  2. // Util.h
  3. //
  4. #ifndef __UTIL_H__
  5. #define __UTIL_H__
  6. #include <stdarg.h>
  7. #ifdef __cplusplus
  8. #define EXTERN_C extern "C"
  9. #else
  10. #define EXTERN_C
  11. #endif
  12. #ifndef _countof
  13. #define _countof(ar) (sizeof(ar) / sizeof((ar)[0]))
  14. #endif
  15. #ifndef _lengthof
  16. #define _lengthof(sz) (_countof(sz) - 1)
  17. #endif
  18. #ifndef ROUND_UP
  19. #define ROUND_UP(val, quantum) ((val) + (((quantum) - ((val) % (quantum))) % (quantum)))
  20. #endif
  21. #ifdef __cplusplus
  22. inline BOOL IsWindows9x() { return (GetVersion() >= 0x80000000) ? TRUE : FALSE; }
  23. #else
  24. #define IsWindows9x() ((GetVersion() >= 0x80000000) ? TRUE : FALSE)
  25. #endif
  26. #define RECTWIDTH(rc) ((rc).right - (rc).left)
  27. #define RECTHEIGHT(rc) ((rc).bottom - (rc).top)
  28. #define HARDWAREADDRESSBUFLEN 64
  29. #ifndef STATUS_SUCCESS
  30. #define STATUS_SUCCESS 0x0
  31. #endif
  32. #ifndef GUID_LENGTH
  33. #define GUID_LENGTH 42
  34. #endif
  35. EXTERN_C LPTSTR lstrchr(LPCTSTR pszString, TCHAR ch);
  36. EXTERN_C LPTSTR lstrdup(LPCTSTR psz);
  37. EXTERN_C BOOL MyIsDigit(TCHAR ch);
  38. EXTERN_C int MyAtoi(LPCTSTR psz);
  39. EXTERN_C int CountChars(LPCTSTR psz, TCHAR ch);
  40. EXTERN_C BOOL LoadDllFunctions(LPCTSTR pszDll, LPCSTR pszFunctionNames, FARPROC* prgFunctions);
  41. EXTERN_C int MakePath(LPTSTR pszBuf, LPCTSTR pszFolder, LPCTSTR pszFileTitle);
  42. EXTERN_C HRESULT MakeLnkFile(CLSID clsid, LPCTSTR pszLinkTarget, LPCTSTR pszDescription, LPCTSTR pszFolderPath, LPCTSTR pszFileName);
  43. EXTERN_C LPTSTR FindPartialPath(LPCTSTR pszFullPath, int nDepth);
  44. EXTERN_C LPTSTR FindFileTitle(LPCTSTR pszFullPath);
  45. EXTERN_C LPTSTR FindExtension(LPCTSTR pszFileName);
  46. EXTERN_C BOOL IsFullPath(LPCTSTR pszPath);
  47. EXTERN_C void ShowDlgItem(HWND hwndDlg, int nCtrlID, int nCmdShow);
  48. EXTERN_C HWND GetDlgItemRect(HWND hwndDlg, int nCtrlID, RECT* pRect);
  49. EXTERN_C void GetRelativeRect(HWND hwndCtrl, RECT* pRect);
  50. EXTERN_C void SetDlgItemRect(HWND hwndDlg, int nCtrlID, CONST RECT* pRect);
  51. EXTERN_C BOOL __cdecl FormatDlgItemText(HWND hwnd, int nCtrlID, LPCTSTR pszFormat, ...);
  52. EXTERN_C void FormatWindowTextV(HWND hwnd, LPCTSTR pszFormat, va_list argList);
  53. EXTERN_C LPTSTR __cdecl LoadStringFormat(HINSTANCE hInstance, UINT nStringID, ...);
  54. EXTERN_C int EstimateFormatLength(LPCTSTR pszFormat, va_list argList);
  55. EXTERN_C void CenterWindow(HWND hwnd);
  56. EXTERN_C LPCWSTR FindResourceString(HINSTANCE hInstance, UINT nStringID, int* pcchString, WORD wLangID);
  57. EXTERN_C int GetResourceStringLength(HINSTANCE hInstance, UINT nStringID, WORD wLangID);
  58. EXTERN_C LPTSTR LoadStringAllocEx(HINSTANCE hInstance, UINT nID, WORD wLangID);
  59. EXTERN_C void TrimLeft(LPTSTR pszText);
  60. EXTERN_C void TrimRight(LPTSTR pszText);
  61. EXTERN_C DWORD RegDeleteKeyAndSubKeys(HKEY hkey, LPCTSTR pszSubKey);
  62. EXTERN_C void DrawHollowRect(HDC hdc, const RECT* pRect, int cxLeft, int cyTop, int cxRight, int cyBottom);
  63. EXTERN_C void DrawFastRect(HDC hdc, const RECT* pRect);
  64. EXTERN_C int GetFontHeight(HFONT hFont);
  65. EXTERN_C HRESULT MyGetSpecialFolderPath(int nFolder, LPTSTR pszPath);
  66. EXTERN_C BOOL GetLinkTarget(LPCTSTR pszLinkPath, LPTSTR pszLinkTarget);
  67. #ifdef __cplusplus
  68. EXTERN_C LPBYTE LoadFile(LPCTSTR pszFileName, DWORD* pdwFileSize = NULL);
  69. #else
  70. EXTERN_C LPBYTE LoadFile(LPCTSTR pszFileName, DWORD* pdwFileSize);
  71. #endif
  72. #ifdef __cplusplus
  73. BOOL GetFirstToken(LPCSTR& pszList, TCHAR chSeparator, LPSTR pszBuf, int cchBuf);
  74. inline LPTSTR LoadStringAlloc(HINSTANCE hInst, UINT nStringID)
  75. { return LoadStringAllocEx(hInst, nStringID, 0); }
  76. void ReplaceString(LPTSTR& pszTarget, LPCTSTR pszSource);
  77. #else
  78. #define LoadStringAlloc(hInst, nStringID) LoadStringAllocEx(hInst, nStringID, 0)
  79. #endif
  80. #define DoesFileExist(szFile) (GetFileAttributes(szFile) != 0xFFFFFFFF)
  81. #define INT16_CCH_MAX 6 // -32768
  82. #define INT32_CCH_MAX 11 // -2147483648
  83. #define INT64_CCH_MAX 20 // -9223372036854775808
  84. #define INT128_CCH_MAX 40 // -170141183460469231731687303715884105728
  85. #define INT16X_CCH_MAX 4 // FFFF
  86. #define INT32X_CCH_MAX 8 // FFFFFFFF
  87. #define INT64X_CCH_MAX 16 // FFFFFFFFFFFFFFFF
  88. #define INT128X_CCH_MAX 32 // FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  89. #if defined(WIN64) // REVIEW: I don't know if these values are correct for Win64
  90. #define INT_CCH_MAX INT32_CCH_MAX
  91. #define INTX_CCH_MAX INT32X_CCH_MAX
  92. #define LONG_CCH_MAX INT32_CCH_MAX
  93. #define LONGX_CCH_MAX INT32X_CCH_MAX
  94. #define SHORT_CCH_MAX INT16_CCH_MAX
  95. #define SHORTX_CCH_MAX INT16X_CCH_MAX
  96. #elif defined(WIN32) // Win32
  97. #define INT_CCH_MAX INT32_CCH_MAX
  98. #define INTX_CCH_MAX INT32X_CCH_MAX
  99. #define LONG_CCH_MAX INT32_CCH_MAX
  100. #define LONGX_CCH_MAX INT32X_CCH_MAX
  101. #define SHORT_CCH_MAX INT16_CCH_MAX
  102. #define SHORTX_CCH_MAX INT16X_CCH_MAX
  103. #else // Win16
  104. #define INT_CCH_MAX INT16_CCH_MAX
  105. #define INTX_CCH_MAX INT16X_CCH_MAX
  106. #define LONG_CCH_MAX INT32_CCH_MAX
  107. #define LONGX_CCH_MAX INT32X_CCH_MAX
  108. #define SHORT_CCH_MAX INT16_CCH_MAX
  109. #define SHORTX_CCH_MAX INT16X_CCH_MAX
  110. #endif
  111. inline HRESULT HrFromWin32Error(DWORD dwErr)
  112. {
  113. return HRESULT_FROM_WIN32(dwErr);
  114. }
  115. #endif // !__UTIL_H__