// --------------------------------------------------------------------------- // Comments InternalName ProductName // CompanyName LegalCopyright ProductVersion // FileDescription LegalTrademarks PrivateBuild // FileVersion OriginalFilename SpecialBuild // --------------------------------------------------------------------------- UnicodeString __fastcall TForm1::GetFileVersionField(UnicodeString PathToFile, const wchar_t *DataFileInformation) { UnicodeString RetField; DWORD hVersion, vis; int len = MAX_PATH; wchar_t cFile[MAX_PATH], vn[100], *ver; ; char ret[MAX_PATH]; LPVOID transblock, *vData; UINT vsize; StrCpyW(cFile, PathToFile.w_str()); vis = GetFileVersionInfoSize(cFile, &hVersion); if (vis == 0) return RetField; vData = (LPVOID*)new char[(UINT)vis]; if (!GetFileVersionInfo(cFile, hVersion, vis, vData)) { delete[](char *)vData; return RetField; } StrCpyW(vn, L"\\VarFileInfo\\Translation"); BOOL res = VerQueryValue(vData, vn, &transblock, &vsize); if (!res) { delete[](char *)vData; return RetField; } *(DWORD*)transblock = MAKELONG(HIWORD(*(DWORD*)transblock), LOWORD(*(DWORD*)transblock)); wsprintf(vn, L"\\StringFileInfo\\%08lx\\%s", *(DWORD*)transblock, DataFileInformation); res = VerQueryValue(vData, vn, (LPVOID*)&ver, &vsize); if (!res) { delete[](char *)vData; return RetField; } int vlen = wcslen(ver); if (ret != NULL) { int clen = ((vlen + 1) >= (len - 1)) ? len - 1 : vlen + 1; for (int i = 0; i < clen; i++) ret[i] = ver[i]; ret[len - 1] = 0; } delete[](char *)vData; RetField = ret; if (!RetField.IsEmpty()) return RetField.Trim(); else return RetField; } // ---------------------------------------------------------------------------