本文整理自网络,侵删。
DELPHI获得文件的版本号
以下程序在DELPHI7 W2003测试通过:
function GetFileVersion(AFileName: string): string;
var
n, Len: DWORD;
Buf : PChar;
Value: Pointer;
szName: array [0..255] of Char;
Transstring: string;
begin
Len := GetFileVersionInfoSize(PChar(AFileName), n);
if Len > 0 then
begin
Buf := AllocMem(Len);
if GetFileVersionInfo(Pchar(AFileName), n, Len, Buf) then
begin
Value := nil;
VerQueryValue(Buf, '\VarFileInfo\Translation', Value, Len);
if Value <> nil then
Transstring := IntToHex(MakeLong(HiWord(LongInt(Value^)),
LoWord(LongInt(Value^))),8);
StrPCopy(szName, '\stringFileInfo\' + Transstring + '\FileVersion');
if VerQueryValue(Buf, szName, Value, Len) then
Result := StrPas(Pchar(Value));
end;
FreeMem(Buf, n);
end;
end;
如何用Delphi编程读出一个DLL文件的版本号,请给示例
好,给几个函数还不行,那就给段代码吧:
procedure TForm1.Button1Click(Sender: TObject);
var
dwVerInfoSize, dwVerHnd: DWORD;
hMem: THandle;
lpvMem, lszVer: Pointer;
szGetName: array[0..255] of Char;
cchVer: UINT;
fRet: Boolean;
vsffi: VS_FIXEDFILEINFO;
begin
dwVerInfoSize := GetFileVersionInfoSize('Shell32.dll', dwVerHnd);
if Boolean(dwVerInfoSize) then
begin
hMem := GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpvMem := GlobalLock(hMem);
GetFileVersionInfo('Shell32.dll', dwVerHnd, dwVerInfoSize, lpvMem);
StrCopy(szGetName, '\');
lszVer := nil;
fRet := VerQueryValue(lpvMem, szGetName, lszVer, cchVer);
if fRet and Boolean(cchVer) and Boolean(lszVer) then
begin
vsffi := VS_FIXEDFILEINFO(lszVer^);
ShowMessage('文件版本: ' +
IntToStr(HIWORD(vsffi.dwFileVersionMS)) + '.' +
IntToStr(LOWORD(vsffi.dwFileVersionMS)) + '.' +
IntToStr(HIWORD(vsffi.dwFileVersionLS)) + '.' +
IntToStr(LOWORD(vsffi.dwFileVersionLS)));
end;
GlobalUnlock(hMem);
GlobalFree(hMem);
end;
end;
如何获取一个可执行文件的版本号?
function GetFileVersion(fn: string; var ma, mi, r ,b: integer):boolean;//得到本程序的版本号
var
buf, p: pChar;
sver: ^VS_FIXEDFILEINFO ;
i: LongWord;
begin
i:= GetFileVersionInfoSize(pchar(fn), i);
new(sver);
p:= pchar(sver);
GetMem(buf, i);
ZeroMemory(buf, i);
result:= false;
if GetFileVersionInfo(pchar(fn), 0, 4096, pointer(buf)) then
if VerQueryValue(buf, '\', pointer(sver), i) then begin
ma:= sVer^.dwFileVersionMS shr 16;
mi:= sver^.dwFileVersionMS and $0000ffff;
r:= sver^.dwFileVersionLS shr 16;
b:= sver^.dwFileVersionLS and $0000ffff;
result:= true;
end;
Dispose(p);
FreeMem(buf);
end;
相关阅读 >>
Delphi tcxgrid的tcxgriddbtableview.viewdata.rows跟records有什么区别
Delphi datamodule1 fdconnection1数据库连接
Delphi webbrowser通过遍历id查找元素是否存在
Delphi xe filesizebyname 要引用哪些文件
更多相关阅读请进入《Delphi》频道 >>