Article View: borland.public.cppbuilder.nativeapi
Article #12836Re: This source not work
From: Marcello Scala
Date: Sat, 15 Nov 2003 12:47
Date: Sat, 15 Nov 2003 12:47
172 lines
6351 bytes
6351 bytes
Sorry....some fix:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
const char* InfoStr[] = {"CompanyName", "FileDescription",
"FileVersion", "InternalName", "LegalCopyright", "LegalTradeMarks",
"OriginalFileName", "ProductName", "ProductVersion", "Comments"};
AnsiString ExeName = Application->ExeName;
DWORD dwDummy = 0;
DWORD dwSize = GetFileVersionInfoSize(ExeName.c_str(), &dwDummy);
if( dwSize > 0 )
{
void *pBuf = malloc(dwSize);
if( pBuf )
{
Memo1->Lines->Add("VersionInfoSize = " +
AnsiString(dwSize));
if( GetFileVersionInfo(ExeName.c_str(), dwDummy, dwSize,
pBuf) )
{
for(int i = 0; i < 10; ++i)
{
char *pValue = NULL;
UINT Len = 0;
AnsiString temp = "StringFileInfo\\040904E4\\"; //
only for language English (United States)
temp += InfoStr[i];
if( VerQueryValue(pBuf,
temp.c_str(),(LPVOID*)&pValue, &Len) )
Memo1->Lines->Add(AnsiString(InfoStr[i]) + " = "
+ AnsiString(pValue, Len));
}
}
else
Memo1->Lines->Add("Could not get version information");
free(pBuf);
}
else
Memo1->Lines->Add("Could not allocate memory for version
information");
}
else
Memo1->Lines->Add("No version information found");
}
----------------------------------------------------------------------------
-
Thanks
Marcello
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> ha scritto nel
messaggio news:3fb15c7e$1@newsgroups.borland.com...
>
> "Marcello Scala" <mscala@email.it> wrote in message
> news:3fb15869@newsgroups.borland.com...
>
> > Why C++ Builder, not compile this source? (i found it on
> > the C++ Builder 6 Help)
>
> Because the help is wrong. A lot of examples in the help are wrong, so
> don't rely on them.
>
> > const AnsiString InfoStr[10] = {"CompanyName", "FileDescription",
> > "FileVersion", "InternalName", "LegalCopyright", "LegalTradeMarks",
> > "OriginalFileName", "ProductName", "ProductVersion", "Comments"};
>
> If I remember, there is a known bug with constructing AnsiString arrays
like
> that. I would suggest using char* instead:
>
> const char* InfoStr[] = {...};
>
> > char *ExeName = Application->ExeName.c_str();
>
> You can't do that. ExeName returns a temporary AnsiString. It will go
out
> of scope and be freed as soon as that statement is finished executing,
thus
> your pointer will be left pointing to invalid memory. Store the value to
an
> AnsiString instead.
>
> > DWORD n = GetFileVersionInfoSize(ExeName, n);
>
> 'n' is not defined yet when GetFileVersionInfoSize() is called, so you
can't
> pass 'n' as the second parameter (which is a pointer, btw). You need to
> declare 'n' before you can use it.
>
> > for (i = 0; i < 10; i++)
>
> You did not declare 'i' anywhere before trying to use it.
>
> > char *pValue;
> <snip>
> > if (VerQueryValue(pBuf, temp.c_str(), pValue, Len)
>
> The buffer parameter expects a pointer to a pointer, but you are not
passing
> that. The length parameter expects a pointer to a UINT, but you are not
> passing that.
>
>
> With all of that said, try the following instead:
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> const char* InfoStr[] = {"CompanyName", "FileDescription",
> "FileVersion", "InternalName", "LegalCopyright", "LegalTradeMarks",
> "OriginalFileName", "ProductName", "ProductVersion", "Comments"};
>
> AnsiString ExeName = Application->ExeName;
> DWORD dwDummy = 0;
>
> DWORD dwSize = GetFileVersionInfoSize(ExeName.c_str(), &dwDummy);
> if( dwSize > 0 )
> {
> void *pBuf = malloc(dwSize);
> if( pBuf )
> {
> Memo1->Lines->Add("VersionInfoSize = " +
> AnsiString(dwSize));
>
> if( GetFileVersionInfo(ExeName.c_str(), dwDummy, dwSize,
> pBuf) )
> {
> for(int i = 0; i < 10; ++i)
> {
> char *pValue = NULL;
> UINT Len = 0;
>
> AnsiString temp = "StringFileInfo\\040904E4\\"
> temp += InfoStr[i];
>
> if( VerQueryValue(pBuf, temp.c_str(),
> (LPVOID*)&pValue, &Len) )
> Memo1->Lines->Add(InfoStr[i] + " = " +
> AnsiString(pValue, Len));
> }
> }
> else
> Memo1->Lines->Add("Could not get version
information");
>
> free(pBuf);
> }
> else
> Memo1->Lines->Add("Could not allocate memory for version
> information");
> }
> else
> Memo1->Lines->Add("No version information found");
> }
>
>
> Next time you run into this kind of problem again, I would highly suggest
> that you read the Win32 API documentation, all of this stuff is explained
in
> there.
>
>
> Gambit
>
>
Technical Details
Message-ID:
<3fb6205a@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-mailReferences:
<3fb15869@newsgroups.borland.com> <3fb15c7e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,a4abdff0e2202e6c X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-15 05:09:52 PST From: "Marcello Scala" <mscala@email.it> Newsgroups: borland.public.cppbuilder.nativeapi References: <3fb15869@newsgroups.borland.com> <3fb15c7e$1@newsgroups.borland.com> Subject: Re: This source not work Date: Sat, 15 Nov 2003 13:47:33 +0100 Lines: 174 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 80.180.222.105 Message-ID: <3fb6205a@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1068900442 80.180.222.105 (15 Nov 2003 04:47:22 -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