🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by poojo hackma Wed, 03 May 2006 21:39
GetFileVersionInfoSize for DLL
#3743
Author: poojo hackma
Date: Wed, 03 May 2006 21:39
12 lines
1251 bytes
How do I get the DLL version information from within my DLL?

I want to create a property that others can read to tell what version it is.

I tried
    ::GetFileVersionInfoSize(ParamStr(0).c_str(), &dwHandle);

and

    ::GetFileVersionInfoSize(Application->ExeName.c_str(), &dwHandle);

Both give me the parent executable, not my DLL. 
Re: GetFileVersionInfoSize for DLL
#3744
Author: Ed Mulroy
Date: Wed, 03 May 2006 22:26
25 lines
1694 bytes
You might try this to get the DLL's file name and use the result for the 
parameter in the GetFileVersionInfoSize call.

  extern HINSTANCE _hInstance;
  char module_name[MAX_PATH + 1];

  ::GetModuleFileName(_hInstance, module_name, sizeof(module_name));

.  Ed

> poojo hackma wrote in message
> news:44592306$1@newsgroups.borland.com...
> How do I get the DLL version information from within my DLL?
>
> I want to create a property that others can read to tell what version it 
> is.
>
> I tried
>    ::GetFileVersionInfoSize(ParamStr(0).c_str(), &dwHandle);
>
> and
>
>    ::GetFileVersionInfoSize(Application->ExeName.c_str(), &dwHandle);
>
> Both give me the parent executable, not my DLL.
Re: GetFileVersionInfoSize for DLL
#3745
Author: Remy Lebeau (TeamB)
Date: Wed, 03 May 2006 22:49
68 lines
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
Re: GetFileVersionInfoSize for DLL
#3750
Author: poojo hackma
Date: Thu, 04 May 2006 16:45
10 lines
1346 bytes
Fantastic!

GetModuleFileName worked!

Thanks to you both, especially to Gambit:  It took me a while to get this 
API to work even with those detailed steps.  I'd hate to think how long that 
would have taken me if I only had Borland's Help and the MSDN library to 
guide me.

Go-Go Gadget Gambit! :)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads