[英]Conversion from TCHAR to char* with unicode char support in 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 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.i正在使用此功能瀏覽文件夾當我將其轉換為char * unicode字符替換為(?????)符號時,我正在path(TCHAR)中獲取確切值。
由於您的項目支持Unicode字符,因此應使用WideCharToMultiByte()轉換為char *。 嘗試使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.