From: broznoober on
I have a DLL, built using VC6, and I want to programatically get its
version number. I have searched the web for how to do this, and have
found a bunch of pages saying to use GetFileVersionInfoSize,
GetFileVersionInfo, and VerQueryValue.

However, all of them seem to be written from the point of view of
getting the version of *another* DLL. I want to get the version of a
DLL from within that DLL itself. Is there an easier way to do this
(e.g. something akin to VB6's App.Major and so forth), or do I have to
go the GetFileVersionInfoSize / GetFileVersionInfo / VerQueryValue
route?

In particular, GetFileVersionInfo and ...Size require the pathname of
the DLL in question. So do I seriously have to determine my own
pathname in order to get my own version information?

Assuming that I really do have to use that stuff, is there an easy way
to get the pathname of a DLL from within the DLL itself?

Thanks in advance for any help.
From: Carl Daniel [VC++ MVP] on
broznoober(a)gmail.com wrote:
> I have a DLL, built using VC6, and I want to programatically get its
> version number. I have searched the web for how to do this, and have
> found a bunch of pages saying to use GetFileVersionInfoSize,
> GetFileVersionInfo, and VerQueryValue.
>
> However, all of them seem to be written from the point of view of
> getting the version of *another* DLL. I want to get the version of a
> DLL from within that DLL itself. Is there an easier way to do this
> (e.g. something akin to VB6's App.Major and so forth), or do I have to
> go the GetFileVersionInfoSize / GetFileVersionInfo / VerQueryValue
> route?
>
> In particular, GetFileVersionInfo and ...Size require the pathname of
> the DLL in question. So do I seriously have to determine my own
> pathname in order to get my own version information?

Yes.

>
> Assuming that I really do have to use that stuff, is there an easy way
> to get the pathname of a DLL from within the DLL itself?

Yes, there is.

Use VirtualQuery, passing the address of something (e.g. a function)
declared in your DLL as the 'lpAddress' parameter. After the call, the
BaseAddress field of the MEMORY_BASIC_INFORMATION structure that you
supplied will be the HMODULE of your DLL.

Use GetModuleFileName, passing the HMODULE obtained above to get the full
path to your DLL.

-cd


From: Igor Tandetnik on
broznoober(a)gmail.com wrote:
> Assuming that I really do have to use that stuff, is there an easy way
> to get the pathname of a DLL from within the DLL itself?

GetModuleFileName using HINSTANCE handle passed to your DllMain
(HINSTANCE and HMODULE are interchangeable).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: Anders Karlsson on
On Wed, 7 May 2008 09:04:27 -0700 (PDT), broznoober(a)gmail.com wrote:

> I have a DLL, built using VC6, and I want to programatically get its
> version number. I have searched the web for how to do this, and have
> found a bunch of pages saying to use GetFileVersionInfoSize,
> GetFileVersionInfo, and VerQueryValue.
>
> However, all of them seem to be written from the point of view of
> getting the version of *another* DLL. I want to get the version of a
> DLL from within that DLL itself. Is there an easier way to do this
> (e.g. something akin to VB6's App.Major and so forth), or do I have to
> go the GetFileVersionInfoSize / GetFileVersionInfo / VerQueryValue
> route?
>
> In particular, GetFileVersionInfo and ...Size require the pathname of
> the DLL in question. So do I seriously have to determine my own
> pathname in order to get my own version information?
>
> Assuming that I really do have to use that stuff, is there an easy way
> to get the pathname of a DLL from within the DLL itself?
>
> Thanks in advance for any help.

there is another way to do it, you can have a header with a couple of
define's and a second resource file (.rc2) contaning the versioninfo
block including the header. Including the header in your .cpp lets get
you the version number without having to access the dll/exe

e.g.

version.h
--------------
#define FVERS 2,0,0,1
+ the other version strings like PRODUCTVERSION


..rc2
-----
#include "version.h"

VS_VERSION_INFO VERSIONINFO
FILEVERSION FVERS
[...]


your .cpp file
--------------------

#include "version.h"

hth/Anders.
--
A: People bitching about top-posting

> Q: What's the most annoying thing on USENET?
From: Tom Serface on
You could use this class:

http://www.naughter.com/versioninfo.html

Tom

<broznoober(a)gmail.com> wrote in message
news:63a37037-866f-47bb-be6f-75a014a3633c(a)d1g2000hsg.googlegroups.com...
>I have a DLL, built using VC6, and I want to programatically get its
> version number. I have searched the web for how to do this, and have
> found a bunch of pages saying to use GetFileVersionInfoSize,
> GetFileVersionInfo, and VerQueryValue.
>
> However, all of them seem to be written from the point of view of
> getting the version of *another* DLL. I want to get the version of a
> DLL from within that DLL itself. Is there an easier way to do this
> (e.g. something akin to VB6's App.Major and so forth), or do I have to
> go the GetFileVersionInfoSize / GetFileVersionInfo / VerQueryValue
> route?
>
> In particular, GetFileVersionInfo and ...Size require the pathname of
> the DLL in question. So do I seriously have to determine my own
> pathname in order to get my own version information?
>
> Assuming that I really do have to use that stuff, is there an easy way
> to get the pathname of a DLL from within the DLL itself?
>
> Thanks in advance for any help.