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.

434 lines
9.8 KiB

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