转换为Wide和MessageBox [英] Converting to Wide and MessageBox
问题描述
我正在尝试将8位ASCII转换为宽字符串以显示在消息框中。但是,我正在做的是导致显示中文字符。
tchKey通过MsiGetProperty从Install Shield进来。
这就是我的......
谢谢,
格伦
< pre lang = vb 跨度>>
TCHAR tchKey [MAX_PATH];
char achKey [MAX_PATH];
wchar_t wWork [ 255 ];
...删除代码...
CW2A convKey(tchKey);
strcpy_s(achKey, sizeof (achKey),convKey);
dwBuffer = strlen(achKey);
for ( int iIndex = 0 ; iIndex<( int )dwBuffer; iIndex ++)
{
if (strchr(BASE32_CHARSET,achKey [iIndex])== 0 )
{
strcpy_s(& achKey [iIndex] , sizeof (achKey) - iIndex,& achKey [iIndex + 1 ]);
iIndex--;
dwBuffer--;
}
}
swprintf(wWork, sizeof (wWork),L& amp; quot;%ls& amp; quot;,achKey);
MessageBox(GetForegroundWindow(),
wWork,
TEXT(& amp; quot; Error& amp; quot;),
MB_OK | MB_ICONERROR | MB_APPLMODAL);& lt ; / pre& gt;< / pre>
如果您的编译器设置是ANSI-Code,则必须使用MessageBoxW。 (1字节字符)
这一行错误:
swprintf(wWork,sizeof(wWork),L%ls, achKey);
第一个错误:
参数适用于snwprintf
。
第二个错误:
您在格式中指定了一个宽字符串,但是传递了一个字符串。使用%hs代替%ls。
所以必须是
snwprintf(wWork, sizeof(wWork),L%hs,achKey);
或
swprintf(wWork,L %hs,achKey);
如果不使用Unicode版本,则必须也使用MessageBoxW
并将标题作为宽字符串传递:
MessageBoxW(GetForegroundWindow(),
wWork,
L( 错误),
MB_OK | MB_ICONERROR | MB_APPLMODAL );
Hi,
I'm trying to convert 8 bit ASCII to a Wide Character string to be displayed in a message box. However, what I'm doing is resulting in Chinese characters being displayed instead.
tchKey comes in from Install Shield via a MsiGetProperty.
Here's what I have....
Thank you,
Glenn
<pre lang="vb">
TCHAR tchKey[MAX_PATH];
char achKey[MAX_PATH];
wchar_t wWork[255];
... removed code ...
CW2A convKey(tchKey);
strcpy_s(achKey, sizeof(achKey), convKey);
dwBuffer = strlen(achKey);
for (int iIndex = 0; iIndex < (int)dwBuffer; iIndex++)
{
if (strchr(BASE32_CHARSET, achKey[iIndex]) == 0)
{
strcpy_s(&achKey[iIndex], sizeof(achKey) - iIndex, &achKey[iIndex + 1]);
iIndex--;
dwBuffer--;
}
}
swprintf(wWork, sizeof(wWork), L&quot;%ls&quot;, achKey);
MessageBox(GetForegroundWindow(),
wWork,
TEXT(&quot;Error&quot;),
MB_OK | MB_ICONERROR | MB_APPLMODAL);</pre></pre>
you must use MessageBoxW if your compiler settings are for ANSI-Code. (1 byte char)
This line is wrong:
swprintf(wWork, sizeof(wWork), L"%ls", achKey);
First error:
Parameters are forsnwprintf
.
Second error:
You are specifying a wide string in the format but passing a char string. Use "%hs" instead of "%ls".
So it must be
snwprintf(wWork, sizeof(wWork), L"%hs", achKey);
or
swprintf(wWork, L"%hs", achKey);
[EDIT]
When not using a Unicode build, you must also useMessageBoxW
and pass the title as wide string:
MessageBoxW(GetForegroundWindow(), wWork, L("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL);
这篇关于转换为Wide和MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!