WideCharToMultiByte转换葡萄牙语乱码,跪求解答

wjjll123 2015-04-20 04:27:14
Não pode detetar orientação

wchar_t wText[50] = {L"Não pode detetar orientação"};
DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);
char *psText;
psText = new char[dwNum];
if(!psText)
{
delete []psText;
}
WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);
delete []psText;

最终psText里面的还是乱码。。。中文没问题,就葡萄牙语不行,难道葡萄牙语不能转成单字节的?
...全文
243 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
智能卡_Snooper 2015-04-22
  • 打赏
  • 举报
回复
转换时参数设置成1252,不丢失信息,mbcs工程运行在中文系统下,估计也不会好到哪去,上面写错了参数,应该是936 //ansi_string ( "Não pode detetar orientação" ) //--ansi_string convert utf16-little-endian format input data to ansi format //-- input = 4E 00 E3 00 6F 00 20 00 70 00 6F 00 64 00 65 00 20 00 64 00 65 00 74 00 65 00 74 00 61 00 72 00 20 00 6F 00 72 00 69 00 65 00 6E 00 74 00 61 00 E7 00 E3 00 6F 00 //-- output = 4E E3 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 E7 E3 6F // //-----Final result --- 4E E3 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 E7 E3 6F // //to_ansi_string ( 4E E3 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 E7 E3 6F ) //--to_ansi_string convert ansi format input data to string //-- input = 4E E3 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 E7 E3 6F //-- output = "Não pode detetar orientação" // //-----Final result --- "Não pode detetar orientação" //
智能卡_Snooper 2015-04-22
  • 打赏
  • 举报
回复
//ansi_string ( "Não pode detetar orientação" ) //--ansi_string convert utf16-little-endian format input data to ansi format //-- input = 4E 00 E3 00 6F 00 20 00 70 00 6F 00 64 00 65 00 20 00 64 00 65 00 74 00 65 00 74 00 61 00 72 00 20 00 6F 00 72 00 69 00 65 00 6E 00 74 00 61 00 E7 00 E3 00 6F 00 //-- output = 4E 3F 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 3F 3F 6F // //-----Final result --- 4E 3F 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 3F 3F 6F // //to_ansi_string ( 4E 3F 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 3F 3F 6F ) //--to_ansi_string convert ansi format input data to string //-- input = 4E 3F 6F 20 70 6F 64 65 20 64 65 74 65 74 61 72 20 6F 72 69 65 6E 74 61 3F 3F 6F //-- output = "N?o pode detetar orienta??o" // //-----Final result --- "N?o pode detetar orienta??o" // 第二个字母,ascii码0x00e3,转完了大于127,再转到963就成了问号。
智能卡_Snooper 2015-04-22
  • 打赏
  • 举报
回复
gb汉字库中又没有把所有字符都包进来,举例来说,泰文就不能用gb2312显示,台湾big5中也有部分汉字不在gb2312中,gbk虽然大,也只是包括了中 日 韩三国的 有些国家,比如西欧,他们abcd是小于127的,另外一些字母是大于127的,你想用多字节工程整对了他,不出乱码,基本上没有可能,除非你自绘。
mayudong1 2015-04-21
  • 打赏
  • 举报
回复
转换没问题,但是现实就会有问题 如果都是unicode的,现实就没问题 多字节的话,windows有个设置“控制面板->区域和语言->管理”,非unicode程序使用的语言,这里选成哪个语言,就能正常显示哪个,其他的都会是乱码
wjjll123 2015-04-21
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
使用...W宽字符版的目录和文件操作相关的API。
就是需要转成char*
凌乱哥 2015-04-21
  • 打赏
  • 举报
回复
就是代码页的问题,PT你用1252绝壁OK了,否则就是你的代码有问题。 参考这里面最后的 西欧Windows 代码页
赵4老师 2015-04-21
  • 打赏
  • 举报
回复
引用 9 楼 wjjll123 的回复:
[quote=引用 8 楼 zhao4zhong1 的回复:] 使用...W宽字符版的目录和文件操作相关的API。
就是需要转成char*[/quote] 你知不知道有些Unicode Char在特定语言版的Windows下是根本不可能转成char的?
赵4老师 2015-04-20
  • 打赏
  • 举报
回复
使用...W宽字符版的目录和文件操作相关的API。
wjjll123 2015-04-20
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
对电脑而言没有乱码,只有二进制字节;对人脑才有乱码。啊 GBK:0xB0 0xA1,Unicode-16 LE:0x4A 0x55,Unicode-16 BE:0x55 0x4A,UTF-8:0xE5 0x95 0x8A 仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
void ShowTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = TRUE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;

    system("color F0");
    system("cls");
    HideTheCursor();
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0             , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,10,L"你好",2);
    DeleteObject(hfont);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, JOHAB_CHARSET , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,80,L"\xb7f0\xb7f0\xb2dd\xb2dd",4);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    ShowTheCursor();
    return 0;
}
你意思我懂,但是代码实现不了。。。问题还没没解决
wjjll123 2015-04-20
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
对电脑而言没有乱码,只有二进制字节;对人脑才有乱码。啊 GBK:0xB0 0xA1,Unicode-16 LE:0x4A 0x55,Unicode-16 BE:0x55 0x4A,UTF-8:0xE5 0x95 0x8A 仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
void ShowTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = TRUE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;

    system("color F0");
    system("cls");
    HideTheCursor();
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0             , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,10,L"你好",2);
    DeleteObject(hfont);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, JOHAB_CHARSET , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,80,L"\xb7f0\xb7f0\xb2dd\xb2dd",4);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    ShowTheCursor();
    return 0;
}
问题就是路径中含有我提问中的字符串,转码之后是乱码,路径不能识别了。
赵4老师 2015-04-20
  • 打赏
  • 举报
回复
对电脑而言没有乱码,只有二进制字节;对人脑才有乱码。啊 GBK:0xB0 0xA1,Unicode-16 LE:0x4A 0x55,Unicode-16 BE:0x55 0x4A,UTF-8:0xE5 0x95 0x8A 仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
void ShowTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = TRUE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;

    system("color F0");
    system("cls");
    HideTheCursor();
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0             , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,10,L"你好",2);
    DeleteObject(hfont);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, JOHAB_CHARSET , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,80,L"\xb7f0\xb7f0\xb2dd\xb2dd",4);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    ShowTheCursor();
    return 0;
}
wjjll123 2015-04-20
  • 打赏
  • 举报
回复
引用 2 楼 zgl7903 的回复:
代码页用 860 试试看
试过了,没区别
wjjll123 2015-04-20
  • 打赏
  • 举报
回复
引用 2 楼 zgl7903 的回复:
代码页用 860 试试看
860是什么编码啊?
zgl7903 2015-04-20
  • 打赏
  • 举报
回复
代码页用 860 试试看
wjjll123 2015-04-20
  • 打赏
  • 举报
回复
来个大神帮忙看一下啊

16,372

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧