7 /**********************************************************************
12 * TRUE if CodePage is installed in the system.
17 IsInstalledCP(UINT CodePage)
24 /**********************************************************************
26 * MultiByteToWideChar@24
30 * CP_ACP ANSI code page
31 * CP_MACCP Macintosh code page
32 * CP_OEMCP OEM code page
33 * (UINT) Any installed code page
38 * MB_ERR_INVALID_CHARS
45 * Size of MultiByteStr, or -1 if MultiByteStr is
52 * Size (in WCHAR unit) of WideCharStr, or 0
53 * if the caller just wants to know how large
54 * WideCharStr should be for a successful
58 * 0 on error; otherwise the number of WCHAR written
59 * in the WideCharStr buffer.
62 * A raw converter for now. It assumes lpMultiByteStr is
63 * NEVER multi-byte (that is each input character is
64 * 8-bit ASCII) and is ALWAYS NULL terminated.
65 * FIXME-FIXME-FIXME-FIXME
72 LPCSTR lpMultiByteStr,
77 int InStringLength = 0;
83 * Check the parameters.
85 if (/* --- CODE PAGE --- */
86 ( (CP_ACP != CodePage)
87 && (CP_MACCP != CodePage)
88 && (CP_OEMCP != CodePage)
89 && (FALSE == IsInstalledCP(CodePage)) )
91 || (dwFlags & ~(MB_PRECOMPOSED | MB_COMPOSITE |
92 MB_ERR_INVALID_CHARS | MB_USEGLYPHCHARS))
93 /* --- INPUT BUFFER --- */
94 || (NULL == lpMultiByteStr) )
96 SetLastError (ERROR_INVALID_PARAMETER);
100 * Compute the input buffer length.
102 //if (-1 == cchMultiByte)
103 if (cchMultiByte < 0)
105 InStringLength = lstrlen(lpMultiByteStr) + 1;
109 InStringLength = cchMultiByte;
112 * Does caller query for output
115 if (0 == cchWideChar)
117 //SetLastError(ERROR_SUCCESS); /* according to wine tests this shouldn't be touched on success.
118 return InStringLength;
121 * Is space provided for the translated
124 if (cchWideChar < InStringLength)
126 SetLastError(ERROR_INSUFFICIENT_BUFFER);
130 * Raw 8- to 16-bit conversion.
132 for (cchConverted = 0,
133 r = (PCHAR)lpMultiByteStr,
134 w = (PWCHAR)lpWideCharStr;
136 cchConverted < InStringLength;
145 * Return how many characters we
146 * wrote in the output buffer.
148 //SetLastError(ERROR_SUCCESS); /* according to wine tests this shouldn't be touched on success.
153 /**********************************************************************
155 * WideCharToMultiByte@32
157 * Not yet implemented complete (without NLS so far)
161 * CP_ACP ANSI code page
162 * CP_MACCP Macintosh code page
163 * CP_OEMCP OEM code page
164 * CP_SYMBOL Symbol code page (42)
165 * CP_THREAD_ACP Current thread's ANSI code page
166 * CP_UTF7 Translate using UTF-7
167 * CP_UTF8 Translate using UTF-8
168 * (UINT) Any installed code page
171 * WC_NO_BEST_FIT_CHARS
172 * WC_COMPOSITECHECK Convert composite characters to precomposed characters.
173 * WC_DISCARDNS Discard nonspacing characters during conversion.
174 * WC_SEPCHARS Generate separate characters during conversion. This is the default conversion behavior.
175 * WC_DEFAULTCHAR Replace exceptions with the default character during conversion.
178 * Points to the wide-character string to be converted.
181 * Size (in WCHAR unit) of WideCharStr, or 0
182 * if the caller just wants to know how large
183 * WideCharStr should be for a successful
186 * Points to the buffer to receive the translated string.
188 * Specifies the size in bytes of the buffer pointed to by the
189 * lpMultiByteStr parameter. If this value is zero, the function
190 * returns the number of bytes required for the buffer.
192 * Points to the character used if a wide character cannot be
193 * represented in the specified code page. If this parameter is
194 * NULL, a system default value is used.
197 * Points to a flag that indicates whether a default character was used.
198 * This parameter may be NULL.
199 FIXME: allways set to FALSE.
204 * 0 on error; otherwise the number of bytes written
205 * in the lpMultiByteStr buffer. Or the number of
206 * bytes needed for the lpMultiByteStr buffer if cchMultiByte is zero.
209 * A raw converter for now. It just cuts off the upper 9 Bit.
210 * So the MBCS-string does not contain any LeadCharacters
211 * FIXME - FIXME - FIXME - FIXME
219 LPCWSTR lpWideCharStr,
221 LPSTR lpMultiByteStr,
223 LPCSTR lpDefaultChar,
224 LPBOOL lpUsedDefaultChar
227 int wi, di; // wide counter, dbcs byte count
230 * Check the parameters.
232 if ( /* --- CODE PAGE --- */
233 ( (CP_ACP != CodePage)
234 && (CP_MACCP != CodePage)
235 && (CP_OEMCP != CodePage)
236 && (CP_SYMBOL != CodePage)
237 && (CP_THREAD_ACP != CodePage)
238 && (CP_UTF7 != CodePage)
239 && (CP_UTF8 != CodePage)
240 && (FALSE == IsInstalledCP (CodePage))
243 || (dwFlags & ~(/*WC_NO_BEST_FIT_CHARS
244 |*/ WC_COMPOSITECHECK
250 /* --- INPUT BUFFER --- */
251 || (NULL == lpWideCharStr)
254 SetLastError(ERROR_INVALID_PARAMETER);
258 // for now, make no difference but only convert cut the characters to 7Bit
259 //if (cchWideChar == -1) // assume its a 0-terminated str
260 if (cchWideChar < 0) // assume its a 0-terminated str
261 { // and determine its length
262 // for (cchWideChar=0; lpWideCharStr[cchWideChar]!=0; cchWideChar++)
264 for (cchWideChar = 0; lpWideCharStr[cchWideChar] != 0; cchWideChar++) {
266 cchWideChar++; // length includes the null terminator
269 // user wants to determine needed space
270 if (cchMultiByte == 0)
272 //SetLastError(ERROR_SUCCESS); /* according to wine tests this shouldn't be touched on success.
273 return cchWideChar; // FIXME: determine correct.
275 // the lpWideCharStr is cchWideChar characters long.
276 for (wi=0, di=0; wi<cchWideChar && di<cchMultiByte; ++wi, ++di)
278 // Flag and a not displayable char FIXME
279 /*if( (dwFlags&WC_NO_BEST_FIT_CHARS) && (lpWideCharStr[wi] >127) )
282 *lpUsedDefaultChar = TRUE;
286 // just cut off the upper 9 Bit, since vals>=128 mean LeadByte.
287 lpMultiByteStr[di] = lpWideCharStr[wi] & 0x007F;
289 // has MultiByte exceeded but Wide is still in the string?
290 if (wi < cchWideChar && di >= cchMultiByte)
292 SetLastError(ERROR_INSUFFICIENT_BUFFER);
295 // else return # of bytes wirtten to MBCSbuffer (di)
296 //SetLastError(ERROR_SUCCESS); /* according to wine tests this shouldn't be touched on success.
297 // FIXME: move that elsewhere
298 if (lpUsedDefaultChar != NULL) *lpUsedDefaultChar = FALSE;