Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用c+中的unicode字符支持从TCHAR转换为char*+;_C++_Visual C++ - Fatal编程技术网

C++ 使用c+中的unicode字符支持从TCHAR转换为char*+;

C++ 使用c+中的unicode字符支持从TCHAR转换为char*+;,c++,visual-c++,C++,Visual C++,如何使用unicode字符将TCHAR转换为char*。我使用黄代码 //BROWSE FOLDER - Opens a browse folder dialog. char* browse_folder(void) { char *selected_path = NULL; TCHAR path[MAX_PATH]; BROWSEINFO bi = { 0 }; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; LPITEMIDLIST p

如何使用unicode字符将TCHAR转换为char*。我使用黄代码

//BROWSE FOLDER - Opens a browse folder dialog.
char* browse_folder(void)
{
char *selected_path = NULL;

TCHAR path[MAX_PATH];
BROWSEINFO bi = { 0 };

bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

if (pidl != 0)
{
    // get the name of the folder and put it in path
    SHGetPathFromIDList(pidl, path);

    //Set the current directory to path
    SetCurrentDirectory(path);

    // free memory used
    IMalloc* imalloc = 0;
    if (SUCCEEDED(SHGetMalloc(&imalloc)))
    {
        imalloc->Free(pidl);
        imalloc->Release();
    }
    //selected_path = ;
    USES_CONVERSION;
    selected_path = T2A(path);
}
}

我已在visual studio项目设置中启用了unicode。我正在使用此功能浏览文件夹。当我将路径(TCHAR)转换为字符时,我将获得路径中的精确值。unicode字符将替换为(????)符号

由于您的项目支持unicode字符,因此应使用WideCharToMultiByte()将其转换为字符*。尝试使用它。

如果您想要字符数据,为什么不使用与windows API函数对应的ansi函数(即SHGetPathFromIDListA、SetCurrentDirectoryA…)呢?为什么混合使用TCHAR和字符?不要认为你应该试着做任何转换。只需将char替换为相应的windows数据类型TCHAR。我在npapi中使用这段代码,npapi需要char指针将此值传递给javascript。