Article View: borland.public.cppbuilder.nativeapi
Article #12869Re: This source not work
From: Remy Lebeau (TeamB)
Date: Tue, 11 Nov 2003 22:05
Date: Tue, 11 Nov 2003 22:05
102 lines
4297 bytes
4297 bytes
"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:
<3fb15c7e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fb15869@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-11 14:09:51 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3fb15869@newsgroups.borland.com> Subject: Re: This source not work Date: Tue, 11 Nov 2003 14:05:54 -0800 Lines: 104 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: 67.22.137.149 Message-ID: <3fb15c7e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1068588158 67.22.137.149 (11 Nov 2003 14:02:38 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail