Article View: borland.public.cppbuilder.nativeapi
Article #12417API - Random error retrieving File Version
From: Alain R.
Date: Mon, 08 Dec 2003 07:34
Date: Mon, 08 Dec 2003 07:34
63 lines
2652 bytes
2652 bytes
Hi
When i use GetFileVersionInfo and retrieve all information (privateBuild,
ProductVersion, Comments, FileVersion, CompanyName,...),
sometimes it works perfectly and sometimes it gives me back some crazy
characters like if i have a chinese computer or characterset. :(
here is my little code :
DWORD dwSize;
DWORD dwReserved;
LPVOID lpBuffer;
String TypeInfo[2] =
{"CompanyName", /* 0 */
"FileVersion", /* 1 */
};
String sCompanyName;
String sFileVersion;
// String fichier = "C:\\Windows\\System32\\Kernel32.dll"; // work
perfectly with this file
String fichier = "C:\\Windows\\System32\\Obdcjt3232.DLL"; // crazy
characters as result
dwSize = GetFileVersionInfoSize(fichier.c_str(), &dwReserved );
lpBuffer = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize );
if ( lpBuffer && GetFileVersionInfo(fichier.c_str(), 0, dwSize,
lpBuffer ) )
{
LPVOID lpStr;
UINT dwLength;
String MessageInfo="";
String Info = "\\StringFileInfo\\040904b0\\";
String TypeInformation;
for (int i=0; i<2; i++)
{
TypeInformation = Info;
TypeInformation += TypeInfo[i];
VerQueryValue(lpBuffer, TypeInformation.c_str() , &lpStr, &dwLength );
if (TypeInfo[i]=="CompanyName")
{
// ok
sCompanyName = AnsiString((LPTSTR)(LPARAM)lpStr);
MessageInfo += "Company Name : " + sCompanyName +"\n\n";
}
else if (TypeInfo[i]=="FileVersion")
{
// ok
sFileVersion = AnsiString((LPTSTR)(LPARAM)lpStr);
MessageInfo += "File Version : " + sFileVersion +"\n\n";
}
}
ShowMessage(MessageInfo);
}
if ( lpBuffer )
{
HeapFree( GetProcessHeap(), 0, lpBuffer );
}
Technical Details
Message-ID:
<3fd42976$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,59dc320eac75a4ea,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-12-07 23:39:12 PST From: "Alain R." <no.valid@email.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: API - Random error retrieving File Version Date: Mon, 8 Dec 2003 08:34:14 +0100 Lines: 67 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 62.168.93.157 Message-ID: <3fd42976$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1070868854 62.168.93.157 (7 Dec 2003 23:34:14 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail