Article View: borland.public.cppbuilder.nativeapi
Article #3745Re: GetFileVersionInfoSize for DLL
From: Remy Lebeau (TeamB)
Date: Wed, 03 May 2006 22:49
Date: Wed, 03 May 2006 22:49
68 lines
3127 bytes
3127 bytes
"poojo hackma" <poojo.com/mail> wrote in message
news:44592306$1@newsgroups.borland.com...
> ::GetFileVersionInfoSize(ParamStr(0).c_str(), &dwHandle);
ParamStr(0) returns the filename for the calling process (the .exe), not the
calling module (the .dll in this case). In order to get the filename of the
DLL from inside the DLL itself, you have to call the Win32 API
GetModuleFileName() function directly, specifying the HINSTANCE that is
given to the DLL as a parameter to its DllEntryPoint() function. For
example:
char szVersion[64] = {0};
BOOL WINAPI DllEntryPoint(HINSTANCE hinst, DWORD fdwReason, LPVOID
lpvReserved)
{
if( fdwReason == DLL_PROCESS_ATTACH )
{
TCHAR szFileName[MAX_PATH+1] = {0};
if( ::GetModuleFileName(hinst, szFileName, MAX_PATH) )
{
DWORD dwHandle = 0;
DWORD dwSize = ::GetFileVersionInfoSize(szFileName,
&dwHandle);
if( dwSize )
{
LPVOID lpData = ::LocalAlloc(LMEM_FIXED, dwSize);
if( lpData )
{
if( ::GetFileVersionInfo(szFileName, dwHandle,
dwSize, lpData) )
{
VS_FIXEDFILEINFO *pVersion = NULL;
UINT uLen = 0;
if( ::VerQueryValue(lpData, TEXT("\\"),
(LPVOID*)&pVersion, &uLen) )
{
sprintf(szVersion, "%hu.%hu.%hu.%hu",
HIWORD(pVersion->dwFileVersionMS), LOWORD(pVersion->dwFileVersionMS),
HIWORD(pVersion->dwFileVersionLS), LOWORD(pVersion->dwFileVersionLS));
}
}
::LocalFree(lpData);
}
}
}
return TRUE;
}
extern "C" void __stdcall GetVersion(char *Buffer, int BufSize)
{
strncpy(Buffer, szVersion, BufSize);
}
> ::GetFileVersionInfoSize(Application->ExeName.c_str(), &dwHandle);
The ExeName property calls ParamStr(0) internally, so the above applies here
as well.
Gambit
Technical Details
Message-ID:
<445933f8$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<44592306$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,440901ce027e115d X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <44592306$1@newsgroups.borland.com> Subject: Re: GetFileVersionInfoSize for DLL Date: Wed, 3 May 2006 15:49:09 -0700 Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <445933f8$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1146696696 68.69.17.41 (3 May 2006 15:51:36 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail