Discussion:
Converting codepage 932->50222
(too old to reply)
Jeff McKay
2007-01-05 00:38:55 UTC
Permalink
Hello, I have a need to convert text encoded in ANSI/OEM Japanese (codepage
932)
into ISO-2022-JP (codepage 50220). I attempt to do this by running the text
through
MultiByteToWideChar with code page 932 (this works). Then I take the output
of that
and try WideCharToMultiByte with code page 50220. This fails with a
GetLastError code
of 87 (invalid parameter). Does it make any sense that 50220 would not be
supported?
I believe I do have all the codepages installed in Windows. I have used
this exact same
routine to convert in the other direction, i.e. 50220 -> 932 and it works
fine. So what
could be going wrong?
Norman Diamond
2007-01-05 01:13:31 UTC
Permalink
Without seeing your code, the only obvious guess is this:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_2bj9.asp
* For the code pages listed below, dwFlags must be 0. Otherwise, the
* function fails with ERROR_INVALID_FLAGS.
* 50220
[...]
Post by Jeff McKay
Hello, I have a need to convert text encoded in ANSI/OEM Japanese (codepage
932)
into ISO-2022-JP (codepage 50220). I attempt to do this by running the text
through
MultiByteToWideChar with code page 932 (this works). Then I take the output
of that
and try WideCharToMultiByte with code page 50220. This fails with a
GetLastError code
of 87 (invalid parameter). Does it make any sense that 50220 would not be
supported?
I believe I do have all the codepages installed in Windows. I have used
this exact same
routine to convert in the other direction, i.e. 50220 -> 932 and it works
fine. So what
could be going wrong?
Jeff McKay
2007-01-05 17:49:34 UTC
Permalink
As I mentioned, the error code I get is 87 decimal, which corresponds to
ERROR_INVALID_PARAMETER, not ERROR_INVALID_FLAGS. I am indeed
setting dwFlags to 0. My conclusion is that WideCharToMultiByte is
faulty, and does not support code page 50220. I hope I'm wrong - If I have
made some coding error, I would be grateful if someone can point it out -
below is the code. "instr" is the input buffer, CPSIZE is set to 16k.
FromCodpage
is 932 and ToCodepage is 50220.
----
ret = MultiByteToWideChar(FromCodepage, 0, instr, -1, (LPWSTR)tbuf,
CPSIZE);
if (ret == 0) {
dret = GetLastError();
com_Log("debug: MultiByteToWideChar failed: %ld", dret);
return(0);
}

ret = WideCharToMultiByte(ToCodepage, 0, (LPWSTR)tbuf, -1, instr, CPSIZE,
NULL, &flag);
if (ret == 0) {
dret = GetLastError();
com_Log("debug: WideCharToMultiByte failed: %ld", dret);
return(0);

-----
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_2bj9.asp
Post by Norman Diamond
* For the code pages listed below, dwFlags must be 0. Otherwise, the
* function fails with ERROR_INVALID_FLAGS.
* 50220
[...]
Norman Diamond
2007-01-09 04:45:05 UTC
Permalink
(1) I think this MSDN statement is relevant:
* For the code pages mentioned in dwFlags, lpUsedDefaultChar must be NULL,
* otherwise the function fails with ERROR_INVALID_PARAMETER.

(2) This code:
(LPWSTR)tbuf
makes it look like someone's trying to cover up a bug, changing a
compile-time error into a logic error or crash. This has nothing to do with
the preceding issue (except possibly by an unlikely combination of
coincidences).
Post by Jeff McKay
As I mentioned, the error code I get is 87 decimal, which corresponds to
ERROR_INVALID_PARAMETER, not ERROR_INVALID_FLAGS. I am indeed
setting dwFlags to 0. My conclusion is that WideCharToMultiByte is
faulty, and does not support code page 50220. I hope I'm wrong - If I have
made some coding error, I would be grateful if someone can point it out -
below is the code. "instr" is the input buffer, CPSIZE is set to 16k.
FromCodpage
is 932 and ToCodepage is 50220.
----
ret = MultiByteToWideChar(FromCodepage, 0, instr, -1, (LPWSTR)tbuf,
CPSIZE);
if (ret == 0) {
dret = GetLastError();
com_Log("debug: MultiByteToWideChar failed: %ld", dret);
return(0);
}
ret = WideCharToMultiByte(ToCodepage, 0, (LPWSTR)tbuf, -1, instr, CPSIZE,
NULL, &flag);
if (ret == 0) {
dret = GetLastError();
com_Log("debug: WideCharToMultiByte failed: %ld", dret);
return(0);
-----
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_2bj9.asp
Post by Norman Diamond
* For the code pages listed below, dwFlags must be 0. Otherwise, the
* function fails with ERROR_INVALID_FLAGS.
* 50220
[...]
Jeff McKay
2007-01-10 19:26:24 UTC
Permalink
I'll be danged, I didn't see that about lpUsedDefaultChar - changing it to
NULL
does in fact fix the problem. Thanks.
Post by Norman Diamond
* For the code pages mentioned in dwFlags, lpUsedDefaultChar must be NULL,
* otherwise the function fails with ERROR_INVALID_PARAMETER.
(LPWSTR)tbuf
makes it look like someone's trying to cover up a bug, changing a
compile-time error into a logic error or crash. This has nothing to do with
the preceding issue (except possibly by an unlikely combination of
coincidences).
Continue reading on narkive:
Loading...