Leaked source code of windows server 2003
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.

329 lines
11 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. #define CmCompareString CmCompareStringW
  71. #else
  72. #define CmStrTrim CmStrTrimA
  73. #define CmIsSpace CmIsSpaceA
  74. #define CmIsDigit CmIsDigitA
  75. #define CmEndOfStr CmEndOfStrA
  76. #define CmAtol CmAtolA
  77. #define CmStrStr CmStrStrA
  78. #define CmStrchr CmStrchrA
  79. #define CmStrrchr CmStrrchrA
  80. #define CmStrtok CmStrtokA
  81. #define CmStrCpyAlloc CmStrCpyAllocA
  82. #define CmStrCatAlloc CmStrCatAllocA
  83. #define CmLoadString CmLoadStringA
  84. #define CmParsePath CmParsePathA
  85. #define CmConvertRelativePath CmConvertRelativePathA
  86. #define CmStripPathAndExt CmStripPathAndExtA
  87. #define CmStripFileName CmStripFileNameA
  88. #define CmBuildFullPathFromRelative CmBuildFullPathFromRelativeA
  89. #define CmFmtMsg CmFmtMsgA
  90. #define CmLoadImage CmLoadImageA
  91. #define CmLoadIcon CmLoadIconA
  92. #define CmLoadSmallIcon CmLoadSmallIconA
  93. #define CmCompareString CmCompareStringA
  94. #endif
  95. //+----------------------------------------------------------------------------
  96. // typedefs
  97. //+----------------------------------------------------------------------------
  98. //+----------------------------------------------------------------------------
  99. // declarations
  100. //+----------------------------------------------------------------------------
  101. CMUTILAPI int WzToSz(IN LPCWSTR pszwStrIn, OUT LPSTR pszStrOut, IN int nOutBufferSize);
  102. CMUTILAPI int SzToWz(IN LPCSTR pszInput, OUT LPWSTR pszwOutput, IN int nBufferSize);
  103. CMUTILAPI LPSTR WzToSzWithAlloc(LPCWSTR pszwWideString);
  104. CMUTILAPI LPWSTR SzToWzWithAlloc(LPCSTR pszAnsiString);
  105. CMUTILAPI DWORD WINAPI GetOSVersion(void);
  106. CMUTILAPI DWORD WINAPI GetOSBuildNumber(void);
  107. CMUTILAPI DWORD WINAPI GetOSMajorVersion(void);
  108. CMUTILAPI BOOL WINAPI IsFarEastNonOSR2Win95(void);
  109. CMUTILAPI HRESULT ReleaseBold(HWND hwnd);
  110. CMUTILAPI HRESULT MakeBold (HWND hwnd, BOOL fSize);
  111. CMUTILAPI void UpdateFont(HWND hDlg);
  112. CMUTILAPI int WzToSz(IN LPCWSTR pszwStrIn, OUT LPSTR pszStrOut, IN int nOutBufferSize);
  113. CMUTILAPI int SzToWz(IN LPCSTR pszInput, OUT LPWSTR pszwOutput, IN int nBufferSize);
  114. CMUTILAPI LPSTR WzToSzWithAlloc(LPCWSTR pszwWideString);
  115. CMUTILAPI LPWSTR SzToWzWithAlloc(LPCSTR pszAnsiString);
  116. CMUTILAPI BOOL CmWinHelp(HWND hWndMain, HWND hWndItem, CONST WCHAR *lpszHelp, UINT uCommand, ULONG_PTR dwData);
  117. CMUTILAPI BOOL IsLogonAsSystem();
  118. //
  119. // Ansi Functions
  120. //
  121. CMUTILAPI LPSTR CmLoadStringA(HINSTANCE hInst, UINT nId);
  122. CMUTILAPI void WINAPI CmStrTrimA(LPSTR);
  123. CMUTILAPI BOOL WINAPI CmIsSpaceA(LPSTR);
  124. CMUTILAPI BOOL WINAPI CmIsDigitA(LPSTR);
  125. CMUTILAPI LPSTR WINAPI CmEndOfStrA(LPSTR);
  126. CMUTILAPI LONG WINAPI CmAtolA(LPCSTR);
  127. CMUTILAPI LPSTR CmStrStrA(LPCSTR, LPCSTR);
  128. CMUTILAPI LPSTR WINAPI CmStrchrA(LPCSTR, CHAR);
  129. CMUTILAPI LPSTR CmStrrchrA(LPCSTR, CHAR);
  130. CMUTILAPI LPSTR CmStrtokA(LPSTR, LPCSTR);
  131. CMUTILAPI LPSTR CmStrCpyAllocA(LPCSTR);
  132. CMUTILAPI LPSTR CmStrCatAllocA(LPSTR *ppszDst, LPCSTR pszSrc);
  133. CMUTILAPI LPSTR CmFmtMsgA(HINSTANCE hInst, DWORD dwMsgId, ...);
  134. CMUTILAPI HANDLE CmLoadImageA(HINSTANCE hMainInst, LPCSTR pszSpec, UINT nResType, UINT nCX, UINT nCY);
  135. CMUTILAPI HICON CmLoadIconA(HINSTANCE hInst, LPCSTR pszSpec);
  136. CMUTILAPI HICON CmLoadSmallIconA(HINSTANCE hInst, LPCSTR pszSpec);
  137. CMUTILAPI BOOL CmParsePathA(LPCSTR pszCmdLine, LPCSTR pszServiceFile, LPSTR *ppszCommand, LPSTR *ppszArguments);
  138. CMUTILAPI LPSTR CmConvertRelativePathA(LPCSTR pszServiceFile, LPSTR pszRelative);
  139. CMUTILAPI LPSTR CmStripPathAndExtA(LPCSTR pszFileName);
  140. CMUTILAPI LPSTR CmStripFileNameA(LPCSTR pszFullNameAndPath, BOOL fKeepSlash);
  141. CMUTILAPI LPSTR CmBuildFullPathFromRelativeA(LPCSTR pszFullFileName, LPCSTR pszRelative);
  142. CMUTILAPI int CmCompareStringA(LPCSTR lpString1, LPCSTR lpString2);
  143. //
  144. // Unicode Functions
  145. //
  146. CMUTILAPI LPWSTR CmLoadStringW(HINSTANCE hInst, UINT nId);
  147. CMUTILAPI void WINAPI CmStrTrimW(LPWSTR);
  148. CMUTILAPI BOOL WINAPI CmIsSpaceW(LPWSTR);
  149. CMUTILAPI BOOL WINAPI CmIsDigitW(LPWSTR);
  150. CMUTILAPI LPWSTR WINAPI CmEndOfStrW(LPWSTR);
  151. CMUTILAPI LONG WINAPI CmAtolW(LPCWSTR);
  152. CMUTILAPI LPWSTR CmStrStrW(LPCWSTR, LPCWSTR);
  153. CMUTILAPI LPWSTR WINAPI CmStrchrW(LPCWSTR, WCHAR);
  154. CMUTILAPI LPWSTR CmStrrchrW(LPCWSTR, WCHAR);
  155. CMUTILAPI LPWSTR CmStrtokW(LPWSTR, LPCWSTR);
  156. CMUTILAPI LPWSTR CmStrCpyAllocW(LPCWSTR);
  157. CMUTILAPI LPWSTR CmStrCatAllocW(LPWSTR *ppszDst, LPCWSTR pszSrc);
  158. CMUTILAPI LPWSTR CmFmtMsgW(HINSTANCE hInst, DWORD dwMsgId, ...);
  159. CMUTILAPI HANDLE CmLoadImageW(HINSTANCE hMainInst, LPCWSTR pszSpec, UINT nResType, UINT nCX, UINT nCY);
  160. CMUTILAPI HICON CmLoadIconW(HINSTANCE hInst, LPCWSTR pszSpec);
  161. CMUTILAPI HICON CmLoadSmallIconW(HINSTANCE hInst, LPCWSTR pszSpec);
  162. CMUTILAPI BOOL CmParsePathW(LPCWSTR pszCmdLine, LPCWSTR pszServiceFile, LPWSTR *ppszCommand, LPWSTR *ppszArguments);
  163. CMUTILAPI LPWSTR CmConvertRelativePathW(LPCWSTR pszServiceFile, LPWSTR pszRelative);
  164. CMUTILAPI LPWSTR CmStripPathAndExtW(LPCWSTR pszFileName);
  165. CMUTILAPI LPWSTR CmStripFileNameW(LPCWSTR pszFullNameAndPath, BOOL fKeepSlash);
  166. CMUTILAPI LPWSTR CmBuildFullPathFromRelativeW(LPCWSTR pszFullFileName, LPCWSTR pszRelative);
  167. CMUTILAPI int CmCompareStringW(LPCWSTR lpString1, LPCWSTR lpString2);
  168. //
  169. // If DEBUG_MEM is defined, used a different set of functions
  170. // to track memory
  171. //
  172. #if defined(DEBUG) && defined(DEBUG_MEM)
  173. CMUTILAPI void* AllocDebugMem(long nSize, const char* lpFileName,int nLine);
  174. CMUTILAPI BOOL FreeDebugMem(void* lpMem);
  175. CMUTILAPI void* ReAllocDebugMem(void* lpMem, long nSize, const char* lpFileName,int nLine);
  176. CMUTILAPI BOOL CheckDebugMem();
  177. #define CmMalloc(nSize) AllocDebugMem(nSize,__FILE__, __LINE__)
  178. #define CmFree(lpMem) ((void)FreeDebugMem(lpMem))
  179. #define CmRealloc(pvPtr, nSize) ReAllocDebugMem(pvPtr, nSize,__FILE__, __LINE__)
  180. inline void __cdecl operator delete(void* p) {CmFree(p);}
  181. inline void* __cdecl operator new(size_t nSize, const char* lpszFileName, int nLine)
  182. {
  183. return AllocDebugMem(nSize, lpszFileName, nLine);
  184. }
  185. //
  186. // Redefine new to keep trak of the file name and line number
  187. //
  188. #define DEBUG_NEW new(__FILE__, __LINE__)
  189. #define new DEBUG_NEW
  190. #else
  191. CMUTILAPI void *CmRealloc(void *pvPtr, size_t nBytes);
  192. CMUTILAPI void *CmMalloc(size_t nBytes);
  193. CMUTILAPI void CmFree(void *pvPtr);
  194. #define CheckDebugMem() (TRUE)
  195. inline void __cdecl operator delete(void* p) {CmFree(p);}
  196. inline void* __cdecl operator new( size_t cSize ) { return CmMalloc(cSize); }
  197. #endif
  198. //
  199. // for i386
  200. //
  201. #ifdef _M_IX86
  202. CMUTILAPI PVOID WINAPI CmMoveMemory(
  203. PVOID dst,
  204. CONST PVOID src,
  205. size_t count
  206. );
  207. #else
  208. //
  209. // alpha has native support
  210. //
  211. #define CmMoveMemory MoveMemory
  212. #endif //_M_IX86
  213. //+----------------------------------------------------------------------------
  214. // definitions
  215. //+----------------------------------------------------------------------------
  216. //
  217. // Returns a pseudo-random number 0 through 32767. Taken from the C runtime rand().
  218. //
  219. class CMUTILAPI_CLASS CRandom
  220. {
  221. public:
  222. CRandom(void) { m_uiSeed = GetTickCount(); }
  223. CRandom(UINT uiSeed) { m_uiSeed = uiSeed; }
  224. void Init(DWORD uiSeed) { m_uiSeed = uiSeed; }
  225. int Generate(void) { return(((m_uiSeed = m_uiSeed * 214013L + 2531011L) >> 16) & 0x7fff); }
  226. protected:
  227. UINT m_uiSeed;
  228. };
  229. //
  230. // thread local storage index
  231. //
  232. extern DWORD g_dwTlsIndex;
  233. #endif _CMUTIL_INC_