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.

323 lines
10 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cmutil.h
  4. //
  5. // Module: CMUTIL.DLL
  6. //
  7. // Synopsis: Header file for Private CM APIs
  8. //
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. // Author: henryt Created 03/01/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. #ifndef _CMUTIL_INC_
  15. #define _CMUTIL_INC_
  16. #ifdef _CMUTIL_MODULE_
  17. #define CMUTILAPI /*extern "C" __declspec(dllexport)*/
  18. #define CMUTILAPI_CLASS __declspec(dllexport)
  19. #else
  20. #define CMUTILAPI /*extern "C" __declspec(dllimport)*/
  21. #define CMUTILAPI_CLASS __declspec(dllimport)
  22. #endif
  23. #include "cini.h"
  24. //+----------------------------------------------------------------------------
  25. // defines
  26. //+----------------------------------------------------------------------------
  27. //
  28. // platform ID for WINDOWS98
  29. //
  30. #define VER_PLATFORM_WIN32_WINDOWS98 100
  31. //
  32. // platform ID for WINDOWS Millennium
  33. //
  34. #define VER_PLATFORM_WIN32_MILLENNIUM 200
  35. //
  36. // OS version macros
  37. //
  38. #define OS_NT ((GetOSVersion() == VER_PLATFORM_WIN32_NT))
  39. #define OS_W9X ((GetOSVersion() != VER_PLATFORM_WIN32_NT))
  40. #define OS_NT6 ((GetOSVersion() == VER_PLATFORM_WIN32_NT) && (GetOSMajorVersion() >= 6))
  41. #define OS_NT51 ((GetOSVersion() == VER_PLATFORM_WIN32_NT) && (GetOSMajorVersion() >= 5) && (GetOSBuildNumber() > 2195))
  42. #define OS_NT5 ((GetOSVersion() == VER_PLATFORM_WIN32_NT) && (GetOSMajorVersion() >= 5))
  43. #define OS_NT4 ((GetOSVersion() == VER_PLATFORM_WIN32_NT) && (GetOSMajorVersion() < 5))
  44. #define OS_W2K ((GetOSVersion() == VER_PLATFORM_WIN32_NT) && (GetOSBuildNumber() == 2195))
  45. #define OS_MIL ((GetOSVersion() == VER_PLATFORM_WIN32_MILLENNIUM))
  46. #define OS_W98 ((GetOSVersion() == VER_PLATFORM_WIN32_WINDOWS98) || (GetOSVersion() == VER_PLATFORM_WIN32_MILLENNIUM))
  47. #define OS_W95 ((GetOSVersion() == VER_PLATFORM_WIN32_WINDOWS))
  48. #ifdef UNICODE
  49. #define CmStrTrim CmStrTrimW
  50. #define CmIsSpace CmIsSpaceW
  51. #define CmIsDigit CmIsDigitW
  52. #define CmEndOfStr CmEndOfStrW
  53. #define CmAtol CmAtolW
  54. #define CmStrStr CmStrStrW
  55. #define CmStrchr CmStrchrW
  56. #define CmStrrchr CmStrrchrW
  57. #define CmStrtok CmStrtokW
  58. #define CmStrCpyAlloc CmStrCpyAllocW
  59. #define CmStrCatAlloc CmStrCatAllocW
  60. #define CmLoadString CmLoadStringW
  61. #define CmParsePath CmParsePathW
  62. #define CmConvertRelativePath CmConvertRelativePathW
  63. #define CmStripPathAndExt CmStripPathAndExtW
  64. #define CmStripFileName CmStripFileNameW
  65. #define CmBuildFullPathFromRelative CmBuildFullPathFromRelativeW
  66. #define CmFmtMsg CmFmtMsgW
  67. #define CmLoadImage CmLoadImageW
  68. #define CmLoadIcon CmLoadIconW
  69. #define CmLoadSmallIcon CmLoadSmallIconW
  70. #else
  71. #define CmStrTrim CmStrTrimA
  72. #define CmIsSpace CmIsSpaceA
  73. #define CmIsDigit CmIsDigitA
  74. #define CmEndOfStr CmEndOfStrA
  75. #define CmAtol CmAtolA
  76. #define CmStrStr CmStrStrA
  77. #define CmStrchr CmStrchrA
  78. #define CmStrrchr CmStrrchrA
  79. #define CmStrtok CmStrtokA
  80. #define CmStrCpyAlloc CmStrCpyAllocA
  81. #define CmStrCatAlloc CmStrCatAllocA
  82. #define CmLoadString CmLoadStringA
  83. #define CmParsePath CmParsePathA
  84. #define CmConvertRelativePath CmConvertRelativePathA
  85. #define CmStripPathAndExt CmStripPathAndExtA
  86. #define CmStripFileName CmStripFileNameA
  87. #define CmBuildFullPathFromRelative CmBuildFullPathFromRelativeA
  88. #define CmFmtMsg CmFmtMsgA
  89. #define CmLoadImage CmLoadImageA
  90. #define CmLoadIcon CmLoadIconA
  91. #define CmLoadSmallIcon CmLoadSmallIconA
  92. #endif
  93. //+----------------------------------------------------------------------------
  94. // typedefs
  95. //+----------------------------------------------------------------------------
  96. //+----------------------------------------------------------------------------
  97. // declarations
  98. //+----------------------------------------------------------------------------
  99. CMUTILAPI int WzToSz(IN LPCWSTR pszwStrIn, OUT LPSTR pszStrOut, IN int nOutBufferSize);
  100. CMUTILAPI int SzToWz(IN LPCSTR pszInput, OUT LPWSTR pszwOutput, IN int nBufferSize);
  101. CMUTILAPI LPSTR WzToSzWithAlloc(LPCWSTR pszwWideString);
  102. CMUTILAPI LPWSTR SzToWzWithAlloc(LPCSTR pszAnsiString);
  103. CMUTILAPI DWORD WINAPI GetOSVersion(void);
  104. CMUTILAPI DWORD WINAPI GetOSBuildNumber(void);
  105. CMUTILAPI DWORD WINAPI GetOSMajorVersion(void);
  106. CMUTILAPI BOOL WINAPI IsFarEastNonOSR2Win95(void);
  107. CMUTILAPI HRESULT ReleaseBold(HWND hwnd);
  108. CMUTILAPI HRESULT MakeBold (HWND hwnd, BOOL fSize);
  109. CMUTILAPI void UpdateFont(HWND hDlg);
  110. CMUTILAPI int WzToSz(IN LPCWSTR pszwStrIn, OUT LPSTR pszStrOut, IN int nOutBufferSize);
  111. CMUTILAPI int SzToWz(IN LPCSTR pszInput, OUT LPWSTR pszwOutput, IN int nBufferSize);
  112. CMUTILAPI LPSTR WzToSzWithAlloc(LPCWSTR pszwWideString);
  113. CMUTILAPI LPWSTR SzToWzWithAlloc(LPCSTR pszAnsiString);
  114. CMUTILAPI BOOL CmWinHelp(HWND hWndMain, HWND hWndItem, CONST WCHAR *lpszHelp, UINT uCommand, ULONG_PTR dwData);
  115. CMUTILAPI BOOL IsLogonAsSystem();
  116. //
  117. // Ansi Functions
  118. //
  119. CMUTILAPI LPSTR CmLoadStringA(HINSTANCE hInst, UINT nId);
  120. CMUTILAPI void WINAPI CmStrTrimA(LPSTR);
  121. CMUTILAPI BOOL WINAPI CmIsSpaceA(LPSTR);
  122. CMUTILAPI BOOL WINAPI CmIsDigitA(LPSTR);
  123. CMUTILAPI LPSTR WINAPI CmEndOfStrA(LPSTR);
  124. CMUTILAPI LONG WINAPI CmAtolA(LPCSTR);
  125. CMUTILAPI LPSTR CmStrStrA(LPCSTR, LPCSTR);
  126. CMUTILAPI LPSTR WINAPI CmStrchrA(LPCSTR, CHAR);
  127. CMUTILAPI LPSTR CmStrrchrA(LPCSTR, CHAR);
  128. CMUTILAPI LPSTR CmStrtokA(LPSTR, LPCSTR);
  129. CMUTILAPI LPSTR CmStrCpyAllocA(LPCSTR);
  130. CMUTILAPI LPSTR CmStrCatAllocA(LPSTR *ppszDst, LPCSTR pszSrc);
  131. CMUTILAPI LPSTR CmFmtMsgA(HINSTANCE hInst, DWORD dwMsgId, ...);
  132. CMUTILAPI HANDLE CmLoadImageA(HINSTANCE hMainInst, LPCSTR pszSpec, UINT nResType, UINT nCX, UINT nCY);
  133. CMUTILAPI HICON CmLoadIconA(HINSTANCE hInst, LPCSTR pszSpec);
  134. CMUTILAPI HICON CmLoadSmallIconA(HINSTANCE hInst, LPCSTR pszSpec);
  135. CMUTILAPI BOOL CmParsePathA(LPCSTR pszCmdLine, LPCSTR pszServiceFile, LPSTR *ppszCommand, LPSTR *ppszArguments);
  136. CMUTILAPI LPSTR CmConvertRelativePathA(LPCSTR pszServiceFile, LPSTR pszRelative);
  137. CMUTILAPI LPSTR CmStripPathAndExtA(LPCSTR pszFileName);
  138. CMUTILAPI LPSTR CmStripFileNameA(LPCSTR pszFullNameAndPath, BOOL fKeepSlash);
  139. CMUTILAPI LPSTR CmBuildFullPathFromRelativeA(LPCSTR pszFullFileName, LPCSTR pszRelative);
  140. //
  141. // Unicode Functions
  142. //
  143. CMUTILAPI LPWSTR CmLoadStringW(HINSTANCE hInst, UINT nId);
  144. CMUTILAPI void WINAPI CmStrTrimW(LPWSTR);
  145. CMUTILAPI BOOL WINAPI CmIsSpaceW(LPWSTR);
  146. CMUTILAPI BOOL WINAPI CmIsDigitW(LPWSTR);
  147. CMUTILAPI LPWSTR WINAPI CmEndOfStrW(LPWSTR);
  148. CMUTILAPI LONG WINAPI CmAtolW(LPCWSTR);
  149. CMUTILAPI LPWSTR CmStrStrW(LPCWSTR, LPCWSTR);
  150. CMUTILAPI LPWSTR WINAPI CmStrchrW(LPCWSTR, WCHAR);
  151. CMUTILAPI LPWSTR CmStrrchrW(LPCWSTR, WCHAR);
  152. CMUTILAPI LPWSTR CmStrtokW(LPWSTR, LPCWSTR);
  153. CMUTILAPI LPWSTR CmStrCpyAllocW(LPCWSTR);
  154. CMUTILAPI LPWSTR CmStrCatAllocW(LPWSTR *ppszDst, LPCWSTR pszSrc);
  155. CMUTILAPI LPWSTR CmFmtMsgW(HINSTANCE hInst, DWORD dwMsgId, ...);
  156. CMUTILAPI HANDLE CmLoadImageW(HINSTANCE hMainInst, LPCWSTR pszSpec, UINT nResType, UINT nCX, UINT nCY);
  157. CMUTILAPI HICON CmLoadIconW(HINSTANCE hInst, LPCWSTR pszSpec);
  158. CMUTILAPI HICON CmLoadSmallIconW(HINSTANCE hInst, LPCWSTR pszSpec);
  159. CMUTILAPI BOOL CmParsePathW(LPCWSTR pszCmdLine, LPCWSTR pszServiceFile, LPWSTR *ppszCommand, LPWSTR *ppszArguments);
  160. CMUTILAPI LPWSTR CmConvertRelativePathW(LPCWSTR pszServiceFile, LPWSTR pszRelative);
  161. CMUTILAPI LPWSTR CmStripPathAndExtW(LPCWSTR pszFileName);
  162. CMUTILAPI LPWSTR CmStripFileNameW(LPCWSTR pszFullNameAndPath, BOOL fKeepSlash);
  163. CMUTILAPI LPWSTR CmBuildFullPathFromRelativeW(LPCWSTR pszFullFileName, LPCWSTR pszRelative);
  164. //
  165. // If DEBUG_MEM is defined, used a different set of functions
  166. // to track memory
  167. //
  168. #if defined(DEBUG) && defined(DEBUG_MEM)
  169. CMUTILAPI void* AllocDebugMem(long nSize, const char* lpFileName,int nLine);
  170. CMUTILAPI BOOL FreeDebugMem(void* lpMem);
  171. CMUTILAPI void* ReAllocDebugMem(void* lpMem, long nSize, const char* lpFileName,int nLine);
  172. CMUTILAPI BOOL CheckDebugMem();
  173. #define CmMalloc(nSize) AllocDebugMem(nSize,__FILE__, __LINE__)
  174. #define CmFree(lpMem) ((void)FreeDebugMem(lpMem))
  175. #define CmRealloc(pvPtr, nSize) ReAllocDebugMem(pvPtr, nSize,__FILE__, __LINE__)
  176. inline void __cdecl operator delete(void* p) {CmFree(p);}
  177. inline void* __cdecl operator new(size_t nSize, const char* lpszFileName, int nLine)
  178. {
  179. return AllocDebugMem(nSize, lpszFileName, nLine);
  180. }
  181. //
  182. // Redefine new to keep trak of the file name and line number
  183. //
  184. #define DEBUG_NEW new(__FILE__, __LINE__)
  185. #define new DEBUG_NEW
  186. #else
  187. CMUTILAPI void *CmRealloc(void *pvPtr, size_t nBytes);
  188. CMUTILAPI void *CmMalloc(size_t nBytes);
  189. CMUTILAPI void CmFree(void *pvPtr);
  190. #define CheckDebugMem() (TRUE)
  191. inline void __cdecl operator delete(void* p) {CmFree(p);}
  192. inline void* __cdecl operator new( size_t cSize ) { return CmMalloc(cSize); }
  193. #endif
  194. //
  195. // for i386
  196. //
  197. #ifdef _M_IX86
  198. CMUTILAPI PVOID WINAPI CmMoveMemory(
  199. PVOID dst,
  200. CONST PVOID src,
  201. size_t count
  202. );
  203. #else
  204. //
  205. // alpha has native support
  206. //
  207. #define CmMoveMemory MoveMemory
  208. #endif //_M_IX86
  209. //+----------------------------------------------------------------------------
  210. // definitions
  211. //+----------------------------------------------------------------------------
  212. //
  213. // Returns a pseudo-random number 0 through 32767. Taken from the C runtime rand().
  214. //
  215. class CMUTILAPI_CLASS CRandom
  216. {
  217. public:
  218. CRandom(void) { m_uiSeed = GetTickCount(); }
  219. CRandom(UINT uiSeed) { m_uiSeed = uiSeed; }
  220. void Init(DWORD uiSeed) { m_uiSeed = uiSeed; }
  221. int Generate(void) { return(((m_uiSeed = m_uiSeed * 214013L + 2531011L) >> 16) & 0x7fff); }
  222. protected:
  223. UINT m_uiSeed;
  224. };
  225. //
  226. // thread local storage index
  227. //
  228. extern DWORD g_dwTlsIndex;
  229. #endif _CMUTIL_INC_