转换为Wide和MessageBox [英] Converting to Wide and MessageBox

查看:66
本文介绍了转换为Wide和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&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>

解决方案

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 for snwprintf.
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 use MessageBoxW and pass the title as wide string:

MessageBoxW(GetForegroundWindow(),
    wWork,
    L("Error"),
    MB_OK | MB_ICONERROR | MB_APPLMODAL);


这篇关于转换为Wide和MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆