Mega Code Archive

 
Categories / Delphi / Examples
 

Dllversion

> I would like to get the version of dll's on a system before my program > starts. type TFVISubBlock = (sbCompanyName, sbFileDescription, sbFileVersion, sbInternalName, sbLegalCopyright, sbLegalTradeMarks, sbOriginalFilename, sbProductName, sbProductVersion, sbComments); {---------------------------------------------------------------------------------- Description : retrieves selected version information from the specified version-information resource. True on success Parameters : const FullPath : string; the exe or dll full path SubBlock : TFVISubBlock; the requested sub block information ie sbCompanyName var sValue : string the returned string value Error checking : YES Notes : 1. 32bit only ( It does not work with 16-bit Windows file images ) 2. TFVISubBlock is declared as TFVISubBlock = (sbCompanyName, sbFileDescription, sbFileVersion, sbInternalName, sbLegalCopyright, sbLegalTradeMarks, sbOriginalFilename, sbProductName, sbProductVersion, sbComments); Tested : in Delphi 4 only Author : Theo Bebekis <bebekis@otenet.gr> -----------------------------------------------------------------------------------} function Get_FileVersionInfo(const FullPath: string; SubBlock: TFVISubBlock; var sValue: string):boolean; const arStringNames : array[sbCompanyName..sbComments] of string = ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFilename', 'ProductName', 'ProductVersion', 'Comments'); var Dummy : DWORD; iLen : DWORD; pData : PChar; pVersion : Pointer; pdwLang : PDWORD; sLangID : string; sCharsetID : string; pValue : PChar; begin Result := False; { get the size of the size in bytes of the file's version information} iLen := GetFileVersionInfoSize(PChar(FullPath), Dummy); if iLen = 0 then Exit; { get the information } pData := StrAlloc(iLen + 1); if not GetFileVersionInfo(PChar(FullPath), { pointer to filename string } 0, { ignored } iLen, { size of buffer } pData) { pointer to buffer to receive file-version info } then Exit; { get the national ID. retrieve a pointer to an array of language and character-set identifiers. Use these identifiers to create the name of a language-specific structure in the version-information resource} if not VerQueryValue(pData, { address of buffer for version resource (in)} '\VarFileInfo\Translation', { address of value to retrieve (in) } pVersion, { address of buffer for version pointer (out)} iLen ) { address of version-value length buffer (out)} then Exit; { analyze it } pdwLang := pVersion; sLangID := IntToHex(pdwLang^, 8); sCharsetID := Copy(sLangID, 1, 4); sLangID := Copy(sLangID, 5, 4); { get the info for the requested sub block } if not VerQueryValue(pData, PChar('\StringFileInfo\' + sLangID + sCharsetID + '\' + arStringNames[SubBlock]), pVersion, iLen) then Exit; { copy it to sValue } pValue := StrAlloc(iLen + 1); StrLCopy(pValue, pVersion, iLen); sValue := String(pValue); StrDispose(pValue); Result := True; end; Theo ----------------------------------- Theo Bebekis Thessaloniki, Greece bebekis@otenet.gr ----------------------------------- _______________________________________________ Delphi mailing list -> Delphi@elists.org http://elists.org/mailman/listinfo/delphi