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.

404 lines
8.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Forms
  4. // Copyright (C) Microsoft Corporation, 1994-1998
  5. //
  6. // File: unicwrap.h
  7. //
  8. // Contents: Wrappers for all Unicode functions used in the Forms^3 project.
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef _UNICWRAP_H_
  12. #define _UNICWRAP_H_
  13. HFONT WINAPI CreateFontIndirectWrap(CONST LOGFONTW * plfw);
  14. //+---------------------------------------------------------------------------
  15. //
  16. // Class: CConvertStr (CStr)
  17. //
  18. // Purpose: Base class for conversion classes.
  19. //
  20. //----------------------------------------------------------------------------
  21. class CConvertStr
  22. {
  23. public:
  24. operator char *();
  25. protected:
  26. CConvertStr(UINT uCP);
  27. ~CConvertStr();
  28. void Free();
  29. UINT _uCP;
  30. LPSTR _pstr;
  31. char _ach[MAX_PATH * 2];
  32. };
  33. //+---------------------------------------------------------------------------
  34. //
  35. // Member: CConvertStr::CConvertStr
  36. //
  37. // Synopsis: ctor.
  38. //
  39. //----------------------------------------------------------------------------
  40. inline
  41. CConvertStr::CConvertStr(UINT uCP)
  42. {
  43. _uCP = uCP;
  44. _pstr = NULL;
  45. }
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Member: CConvertStr::~CConvertStr
  49. //
  50. // Synopsis: dtor.
  51. //
  52. //----------------------------------------------------------------------------
  53. inline
  54. CConvertStr::~CConvertStr()
  55. {
  56. Free();
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // Member: CConvertStr::operator char *
  61. //
  62. // Synopsis: Returns the string.
  63. //
  64. //----------------------------------------------------------------------------
  65. inline
  66. CConvertStr::operator char *()
  67. {
  68. return _pstr;
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Class: CStrIn (CStrI)
  73. //
  74. // Purpose: Converts string function arguments which are passed into
  75. // a Windows API.
  76. //
  77. //----------------------------------------------------------------------------
  78. class CStrIn : public CConvertStr
  79. {
  80. public:
  81. CStrIn(LPCWSTR pwstr);
  82. CStrIn(LPCWSTR pwstr, int cwch);
  83. CStrIn(UINT uCP, LPCWSTR pwstr);
  84. CStrIn(UINT uCP, LPCWSTR pwstr, int cwch);
  85. int strlen();
  86. protected:
  87. CStrIn();
  88. void Init(LPCWSTR pwstr, int cwch);
  89. int _cchLen;
  90. };
  91. //+---------------------------------------------------------------------------
  92. //
  93. // Member: CStrIn::CStrIn
  94. //
  95. // Synopsis: Inits the class with a given length
  96. //
  97. //----------------------------------------------------------------------------
  98. inline
  99. CStrIn::CStrIn(LPCWSTR pwstr, int cwch) : CConvertStr(CP_ACP)
  100. {
  101. Init(pwstr, cwch);
  102. }
  103. inline
  104. CStrIn::CStrIn(UINT uCP, LPCWSTR pwstr, int cwch) : CConvertStr(uCP)
  105. {
  106. Init(pwstr, cwch);
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Member: CStrIn::CStrIn
  111. //
  112. // Synopsis: Initialization for derived classes which call Init.
  113. //
  114. //----------------------------------------------------------------------------
  115. inline
  116. CStrIn::CStrIn() : CConvertStr(CP_ACP)
  117. {
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Member: CStrIn::strlen
  122. //
  123. // Synopsis: Returns the length of the string in characters, excluding
  124. // the terminating NULL.
  125. //
  126. //----------------------------------------------------------------------------
  127. inline int
  128. CStrIn::strlen()
  129. {
  130. return _cchLen;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Class: CStrInMulti (CStrIM)
  135. //
  136. // Purpose: Converts multiple strings which are terminated by two NULLs,
  137. // e.g. "Foo\0Bar\0\0"
  138. //
  139. //----------------------------------------------------------------------------
  140. class CStrInMulti : public CStrIn
  141. {
  142. public:
  143. CStrInMulti(LPCWSTR pwstr);
  144. };
  145. //+---------------------------------------------------------------------------
  146. //
  147. // Class: CStrOut (CStrO)
  148. //
  149. // Purpose: Converts string function arguments which are passed out
  150. // from a Windows API.
  151. //
  152. //----------------------------------------------------------------------------
  153. class CStrOut : public CConvertStr
  154. {
  155. public:
  156. CStrOut(LPWSTR pwstr, int cwchBuf);
  157. ~CStrOut();
  158. int BufSize();
  159. int ConvertIncludingNul();
  160. int ConvertExcludingNul();
  161. private:
  162. LPWSTR _pwstr;
  163. int _cwchBuf;
  164. };
  165. //+---------------------------------------------------------------------------
  166. //
  167. // Member: CStrOut::BufSize
  168. //
  169. // Synopsis: Returns the size of the buffer to receive an out argument,
  170. // including the terminating NULL.
  171. //
  172. //----------------------------------------------------------------------------
  173. inline int
  174. CStrOut::BufSize()
  175. {
  176. return _cwchBuf * 2;
  177. }
  178. //
  179. // Multi-Byte ---> Unicode conversion
  180. //
  181. //+---------------------------------------------------------------------------
  182. //
  183. // Class: CConvertStrW (CStr)
  184. //
  185. // Purpose: Base class for multibyte conversion classes.
  186. //
  187. //----------------------------------------------------------------------------
  188. class CConvertStrW
  189. {
  190. public:
  191. operator WCHAR *();
  192. protected:
  193. CConvertStrW();
  194. ~CConvertStrW();
  195. void Free();
  196. LPWSTR _pwstr;
  197. WCHAR _awch[MAX_PATH * 2];
  198. };
  199. //+---------------------------------------------------------------------------
  200. //
  201. // Member: CConvertStrW::CConvertStrW
  202. //
  203. // Synopsis: ctor.
  204. //
  205. //----------------------------------------------------------------------------
  206. inline
  207. CConvertStrW::CConvertStrW()
  208. {
  209. _pwstr = NULL;
  210. }
  211. //+---------------------------------------------------------------------------
  212. //
  213. // Member: CConvertStrW::~CConvertStrW
  214. //
  215. // Synopsis: dtor.
  216. //
  217. //----------------------------------------------------------------------------
  218. inline
  219. CConvertStrW::~CConvertStrW()
  220. {
  221. Free();
  222. }
  223. //+---------------------------------------------------------------------------
  224. //
  225. // Member: CConvertStrW::operator WCHAR *
  226. //
  227. // Synopsis: Returns the string.
  228. //
  229. //----------------------------------------------------------------------------
  230. inline
  231. CConvertStrW::operator WCHAR *()
  232. {
  233. return _pwstr;
  234. }
  235. //+---------------------------------------------------------------------------
  236. //
  237. // Class: CStrInW (CStrI)
  238. //
  239. // Purpose: Converts multibyte strings into UNICODE
  240. //
  241. //----------------------------------------------------------------------------
  242. class CStrInW : public CConvertStrW
  243. {
  244. public:
  245. CStrInW(LPCSTR pstr) { Init(pstr, -1); }
  246. CStrInW(LPCSTR pstr, int cch) { Init(pstr, cch); }
  247. int strlen();
  248. protected:
  249. CStrInW();
  250. void Init(LPCSTR pstr, int cch);
  251. int _cwchLen;
  252. };
  253. //+---------------------------------------------------------------------------
  254. //
  255. // Member: CStrInW::CStrInW
  256. //
  257. // Synopsis: Initialization for derived classes which call Init.
  258. //
  259. //----------------------------------------------------------------------------
  260. inline
  261. CStrInW::CStrInW()
  262. {
  263. }
  264. //+---------------------------------------------------------------------------
  265. //
  266. // Member: CStrInW::strlen
  267. //
  268. // Synopsis: Returns the length of the string in characters, excluding
  269. // the terminating NULL.
  270. //
  271. //----------------------------------------------------------------------------
  272. inline int
  273. CStrInW::strlen()
  274. {
  275. return _cwchLen;
  276. }
  277. //+---------------------------------------------------------------------------
  278. //
  279. // Class: CStrOutW (CStrO)
  280. //
  281. // Purpose: Converts returned unicode strings into ANSI. Used for [out]
  282. // params (so we initialize with a buffer that should later be
  283. // filled with the correct ansi data)
  284. //
  285. //
  286. //----------------------------------------------------------------------------
  287. class CStrOutW : public CConvertStrW
  288. {
  289. public:
  290. CStrOutW(LPSTR pstr, int cchBuf);
  291. ~CStrOutW();
  292. int BufSize();
  293. int ConvertIncludingNul();
  294. int ConvertExcludingNul();
  295. private:
  296. LPSTR _pstr;
  297. int _cchBuf;
  298. };
  299. //+---------------------------------------------------------------------------
  300. //
  301. // Member: CStrOutW::BufSize
  302. //
  303. // Synopsis: Returns the size of the buffer to receive an out argument,
  304. // including the terminating NULL.
  305. //
  306. //----------------------------------------------------------------------------
  307. inline int
  308. CStrOutW::BufSize()
  309. {
  310. return _cchBuf;
  311. }
  312. #endif // _UNICWRAP_H_