Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with VerQueryValue Win32 API function n version.dll

308 views
Skip to first unread message

Roumen Ivanov

unread,
Apr 17, 2003, 2:18:32 AM4/17/03
to
Hi,

I am trying to use some Win32 API functions in a Visual Basic 6.0 and
I am getting some errors. What I am trying to do is to get the version
information from an executable, dll or custom control file. I am using
the functions GetFileVersionInfSize, GetFileVersionInfo and
VerQueryValue, which are located in version.dll file. I have no
problems with the first two functions, but when the program reaches
the line where I invoke the VerQueryValue function I get the following
error message:

"Can't find DLL entry point VerQueryValue in version.dll"

In my opinion this message means that the function VerQueryValue
cannot be found in the version.dll, but I don't why.
I am reading Dan Appleman's Visual Basic 5.0 Programmers Guide to the
WIN32 API, but I don't have the book. Instead I have some of the files
from the book's CD-ROM, which a friend of mine gave me. In these files
the most important file is a huge win help file with the name of
vbpg32.hlp, which contains the whole book in electronic format.
Unfortunately I don't have the sample files and projects from the book
and I use examples, which are given in the text in this win help file.
The above problem I got when I tried to do the FileDemo Example
project from Chapter 13 - FileDemo-Initialization File, Registry, and
Version Stamping Program.
I am using a computer with Windows 98 (not Second Edition) at my job.
I tried the same FileDemo project also at my home machine, which is
running Windows XP, but I am getting the same error message.
Can somebody help me to solve the problem? Also, does anybody know
where I can find information for currently actual Win32 API functions?
I tried Microsoft's MSDN web site, but I couldn't find anything
concerning Win32 API. Instead I found a lot of information concerning
Microsoft's .Net new technology. Dan Appleman's book, which I have in
electronic format is a little bit old, it discusses Visual Basic
versions 4.0 and 5.0. And I live in Bulgaria where is very difficult
to find original computer books.
Thank you for your help.

Roumen Ivanov

John Brown

unread,
Apr 17, 2003, 10:03:36 AM4/17/03
to
> In my opinion this message means that the function VerQueryValue
> cannot be found in the version.dll, but I don't why.

Windows API functions that have string parameters exist in two forms:
one that takes an ANSI string (1-byte characters) and one that takes
Unicode strings (2-byte or "Wide" characters). So version.dll actually
contains VerQueryValueA and VerQueryValueW, and not VerQueryValue.

From Visual Basic, you should use the ANSI version of the function, so
you will need to use the "Alias" keyword ,e.g.

Declare Function VerQueryValue Lib "version.dll" Alias
"VerQueryValueA" (pBlock as ...

Jussi Jumppanen

unread,
Apr 22, 2003, 9:40:06 PM4/22/03
to
Roumen Ivanov wrote:

> I am trying to use some Win32 API functions in a Visual Basic 6.0 and
> I am getting some errors. What I am trying to do is to get the version
> information from an executable, dll or custom control file. I am using
> the functions GetFileVersionInfSize, GetFileVersionInfo and
> VerQueryValue, which are located in version.dll file.

No they are not :)

You need to look for GetFileVersionInfSizeA, GetFileVersionInfoA
and VerQueryValueA instead.

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, Emacs, etc) FTP Text Editor
"The C/C++, Java, HTML, FTP, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com

Roumen Ivanov

unread,
Apr 22, 2003, 2:34:19 PM4/22/03
to
Dear Jhon, Jussi et others,

Thank you very much for your help for using Win32 API VerQueryValue
function. You are right I had to add the:

Alias "VerQueryValueA"

to the declaration of the function. Actually I did it before posting
my message to the news group but I forgot to mention that it crashed
the Visual Basic. After adding the "Alias ..." part to the declaration
of the function and seeing that my program crashes on the row where I
invoke VerQueryValue function, I decided to trace the program and to
read the description of VerQueryValue function in Dan Appleman's
e-book that I have. I noticed that Visual Basic's API Viewer
absolutely deceives the programmer. If you insert the declaration of
the VerQueryValue function that API Viewer suggests your program will
crash. Firstly, because the API viewer uses the "Alias ..." part
incorrectly and secondly, because it mistakenly declares the
lplpBuffer parameter as "ByVal". The declaration of VerQueryValue
function that API viewer offers is:

Public Declare Function VerQueryValue Lib "version.dll" Alias
"VerQueryValue" (pBlock As Any, ByVal lpSubBlock As String, ByVal
lplpBuffer As Long, puLen As Long) As Long

It is absolutely incorrect! The correct declaration is:

Public Declare Function VerQueryValue Lib "version.dll" Alias
"VerQueryValueA" _
(pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Long, _
puLen As Long) As Long

The lplpBuffer variable is: "The address of the long variable to load
with the address of a buffer to load with the requested version
information." as Dan Appleman writes in his book, so lplpBuffer can
not be declared using "ByVal" keyword.

After correcting the declaration of VerQueryValue function my program
started running correctly. I even corrected another VB project, which
also used the above-mentioned API function and it also started running
OK.

Despite this slight success of using some Win32 API functions in my
Visual Basic projects I still have problems with declaration of some
function parameters with "ByVal" keyword and I even saw that some API
functions use "ByVal" keyword when they are invoked. I still cannot
understand a statement like the following, for example:

agCopyData ByVal fiiaddr&, ByVal tbuf$, fiilen&

This invokes the agCopyData function, which is part of APIGID32.DLL
file, but it uses "ByVal" keyword in the call to the function instead
in its declaration.

Anyway I am going on dealing with Win32 API functions. I hope I'll get
more understanding when I reading and working more with them.
Once again thank you very much!

Roumen

John Brown

unread,
Apr 22, 2003, 6:33:45 PM4/22/03
to
Yes, the API Viewer gets it wrong sometimes.

> agCopyData ByVal fiiaddr&, ByVal tbuf$, fiilen&

You would use ByVal in the call when the parameter was declraed "As
Any". ByVal instructs Visual Basic to pass the value of the variable
to the function. Without the ByVal keyword, the address of the
variable would be passed in the parameter.

This is because the 'C' language, in which the API is defined, allows
you to use pointers, which are the addresses of variables, and there
is the special value NULL, which is equal to 0. It also allows you to
use a pointer to one type of variable in place of a pointer to a
different type. Many API functions allow you to specify a string
(which in C is a pointer) or the address of a struct (a User Defined
Type in Visual Basic). A NULL would indicate that you will accept
certain defaults.

So you could write something like:

'pass the address of MyVar, where MyVar is any type
'including a UDT
MyAPIFunc MyVar

or

'pass the actual value 0, which is teh value of NULL
MyApIFunc ByVal 0&

Also, look at the VarPtr function.

Roumen Ivanov

unread,
May 3, 2003, 11:08:11 AM5/3/03
to
Thank you people for your help!
In another Usenet group I was suggested two very useful sites:

http;//www.allapi.net
http://www.crackinguniversity2000.it/vb_api/ref/v/verqueryvalue.html

They are great!!!
I found them very helpful for me!
Meanwhile, I'm continuing to deal with API and VB, I found more errors
in Microsoft's API Viewer and its database. The declaration of the API
function PtInRect is wrong:

Public Declare Function PtInRect Lib "user32" Alias "PtInRect" (lpRect
As RECT, pt As POINTAPI) As Long

The correct declaration is:

Public Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal
ptx As Long, ByVal pty As Long) As Long

Too many errors from Microsoft! I wasted a lot of time correcting
them. What are they doing? Why didn't they correct their declarations?
But with the help of the above web sites I hope I'll manage to go
ahead in VB and Win32 API world.
Thank you once again!!!

Roumen

0 new messages