Pointer型数据如何正常的取出字符串,现在是乱码
照书上抄的,红色部分是取得字符串的地方,现在取出的字符串是乱码,有什么好办法解决呢?
TListItem *NewItem; AnsiString ExeFile; //存放进程对应的 exe 文件的文件名 PROCESSENTRY32 processinfo; //进程信息结构体 processinfo.dwSize = sizeof(processinfo); //获取系统快照 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(snapshot == NULL) return; bool flag= Process32First(snapshot,&processinfo); while (flag) { NewItem= Form1->ListView2->Items->Add(); ExeFile = AnsiString(processinfo.szExeFile); NewItem->Caption = ExeFile; //进程的 ID,即 PID NewItem->SubItems->Add(IntToStr(int(processinfo.th32ProcessID))); //父进程的 PID NewItem->SubItems->Add(IntToStr(int(processinfo.th32ParentProcessID))); DWORD dwSize,dwSize2; //获取可执行文件的版本等信息 dwSize = GetFileVersionInfoSize(ExeFile.c_str(),&dwSize2); if(dwSize != 0) { Pointer pt = malloc(dwSize); Pointer pt2; unsigned int s; GetFileVersionInfo(ExeFile.c_str(),NULL,dwSize,pt); if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileVersion",&pt2,&s)) [color=#FF0000]NewItem->SubItems->Add(PChar(pt2));[/color] if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\CompanyName",&pt2,&s)) [color=#FF0000]NewItem->SubItems->Add(PChar(pt2));[/color] if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileDescription",&pt2,&s)) [color=#FF0000]NewItem->SubItems->Add(PChar(pt2));[/color] free(pt); } flag = Process32Next(snapshot,&processinfo); } CloseHandle(snapshot);
TListItem *NewItem; AnsiString ExeFile; //存放进程对应的 exe 文件的文件名 PROCESSENTRY32 processinfo; //进程信息结构体 processinfo.dwSize = sizeof(processinfo); //获取系统快照 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(snapshot == NULL) return; bool flag= Process32First(snapshot,&processinfo); while (flag) { NewItem= Form1->ListView2->Items->Add(); ExeFile = AnsiString(processinfo.szExeFile); NewItem->Caption = ExeFile; //进程的 ID,即 PID NewItem->SubItems->Add(IntToStr(int(processinfo.th32ProcessID))); //父进程的 PID NewItem->SubItems->Add(IntToStr(int(processinfo.th32ParentProcessID))); DWORD dwSize,dwSize2; //获取可执行文件的版本等信息 dwSize = GetFileVersionInfoSize(ExeFile.c_str(),&dwSize2); if(dwSize != 0) { Pointer pt = malloc(dwSize); char *pt2; unsigned int s; GetFileVersionInfo(ExeFile.c_str(),NULL,dwSize,pt); if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileVersion",&((void *)pt2),&s)) { NewItem->SubItems->Add(UnicodeString(pt2)); } if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\CompanyName",&((void *)pt2),&s)) { NewItem->SubItems->Add(UnicodeString(pt2)); } if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileDescription",&((void *)pt2),&s)) { NewItem->SubItems->Add(UnicodeString(pt2)); } free(pt); } flag = Process32Next(snapshot,&processinfo); } CloseHandle(snapshot);