2016-02-14 32 views
0

当我想开一家UTF8路径与_popenPOPEN UTF8路径

所以在这里我有一个问题是我的代码:

char buf1520[1500]; 
string testme; 
const char * sroot2 = getenv ("systemroot"); 
string md5cmd2 = sroot2; 
md5cmd2 += "\\System32\\certutil -hashfile "; 
md5cmd2 += "C:\\Users\\Vuzee\\Desktop\\testč\\test.jar"; 
cout << md5cmd2 << endl; 
md5cmd2 += " MD5"; 
const char* md5cmdnovo2 = md5cmd2.c_str(); 
FILE *p1502 = _popen(md5cmdnovo2, "r"); 

for (size_t count; (count = fread(buf1520, 1, sizeof(buf1520), p1502));) 
    testme += string(buf1520, buf1520 + count); 
    _pclose(p1502); 

cout << "HASH:" << testme << endl; 
cin.ignore(); 

在此COUT afther路,我得到这个输出:C:\Windows\System32\certutil -hashfile C:\Users\Vuzee\Desktop\testÄ\test.jar

所以我认为问题是因为字符串不能保存UTF8字符,所以我怎么能解决这个问题,并在popen中调用它?

和去年COUT我得到:

HASH:CertUtil: -hashfile command FAILED: 0x80070003 (WIN32: 3) 
CertUtil: The system cannot find the path specified. 
+0

什么让你觉得UTF-8应的Windows API曾经工作吗? –

+1

在进行文件系统调用之前,您需要将UTF-8转换为UTF-16 LE。 –

回答

0

您的应用程序可以将字符串存储为UTF-8,但Windows操作系统应用界面—的两种口味也不是UTF-8。

您可以使用_wopen函数来处理您的应用程序,该函数处理wchar_t(宽字符)。作为开始,您必须将md5cmd2中的string值转换为宽字符串(铸造为char*将不起作用)。

延伸阅读: