我正在尝试使用VerQueryValue
简体中文操作系统显示 EXE 信息。所有文字显示正确,但版权符号显示为“?” . 这是我正在使用的代码。
const
CInfoStr : array[1..13] of string =
('FileVersion',
'CompanyName',
'FileDescription',
'InternalName',
'LegalCopyright',
'LegalTradeMarks',
'OriginalFileName',
'ProductName',
'ProductVersion',
'Comments',
'CurrentProgramVersion',
'CurrentDatabaseVersion',
'VersionDetails');
type
PTransBuffer = ^TTransBuffer;
TTransBuffer = array[1..13] of smallint;
Function CheckFileVerForAppReplaceAlert(Path : String): Boolean;
var
InfoSize,
VerSize, Wnd : DWORD;
Value : PChar;
ValWide : PWideCHar;
NewValWide : WideString;
VerBuf : pointer;
pTrans : PTransBuffer;
TypeStr,
TransStr : string;
j : Integer;
KeyPath : String;
NewFileVer : String;
OldFileVer : String;
ResVer : Integer;
begin
Result := False;
If Path = '' then
exit;
try
// Get Version of File
InfoSize := GetFileVersioninfoSize(PChar(Path), Wnd);
if (InfoSize <> 0) then
begin
try
GetMem(VerBuf, InfoSize);
if GetFileVersionInfo(PChar(Path), Wnd, InfoSize, VerBuf) then
begin
if VerQueryValue(VerBuf, PChar('\VarFileInfo\Translation'),Pointer(pTrans), VerSize) then
begin
TransStr := IntToHex(pTrans^[1], 4) + IntToHex(pTrans^[2], 4);
TypeStr := 'StringFileInfo\' + TransStr + '\' + CInfoStr[5]; //Get The Copyright
//if VerQueryvalue(VerBuf, PChar(TypeStr),Pointer(Value), VerSize) then
if VerQueryvalue(VerBuf, PChar(TypeStr),Pointer(Value), VerSize) then
begin
NewFileVer := Value;
//NewValWide :=Value;
Updatelog('NewFileVer ' + NewValWide);
// ShowMessage('Copyright ' + NewFileVer);
//MessageBoxW(Application.Handle, PWideCHar(NewFileVer) , PWideChar('Err'),MB_OKCANCEL);
end;
end;
end
finally
Try
FreeMem(VerBuf, InfoSize);
Except
End;
end;
end //end Of taking version
except
end;
end;
这是为宽字符串编写的代码:
Function AddWidePathToAppList_Reg(AppPath : WideString): Boolean ;
Var
j : Integer;
PathWS : WideString;
InfoSize,VerSize, Wnd: DWORD;
pTrans: PTransBuffer;
VerBuf: pointer;
VerFlag: Boolean;
Value: PWChar;
TypeStr,
TransStr: WideString;
Begin
Result := False;
PathWS := (AppPath);
InfoSize := GetFileVersioninfoSizeW(PWChar(AppPath), Wnd);
if (InfoSize <> 0) then
begin
GetMem(VerBuf, InfoSize);
try
if GetFileVersionInfoW(PWChar(AppPath), Wnd, InfoSize, VerBuf) then
begin
if VerQueryValueW(VerBuf, '\VarFileInfo\Translation',Pointer(pTrans), VerSize) then
begin
VerFlag:=False;
TransStr := IntToHex(pTrans^[1], 4) + IntToHex(pTrans^[2], 4);
for j := Low(CInfoStr) to High(CInfoStr) do
begin
TypeStr := 'StringFileInfo\' + TransStr + '\' + CInfoStr[j];
if VerQueryvalueW(VerBuf, PWChar(TypeStr),Pointer(Value), VerSize) then
begin
UpdateLog('Vlaue ' + Value);
Result := True;
end;
end;
end;
end;
finally
FreeMem(VerBuf, InfoSize);
end;
end;
end;
我不明白我在做什么错。我尝试使用 WideString 代替 String。但这没有什么区别。
指导将不胜感激。
提前致谢