Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VerQueryValue Problem 1

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,311
US
I'm trying to get a VerQueryValue call going, but I'm running into a problem getting information on specific executables (for example .NET patches). From what I can tell, there aren't any errors, and the same code works for other executables. I did a dump of the File Version Info for one of the .NET patches and other than some additional version info strings, I notice everything else is the same (even language and code page), which I get by a VerQueryValue call with the translation string.

Any ideas on this one?

(For CompanyName the 867460 .NET SP1 package, would return "M" with a string length of 44 instead of the 22 character string "Microsoft Corporation".)
 
>...would return "M" with a string length of 44 instead of the 22 character string "Microsoft Corporation".

This clue tells a lot. I think somewhere, there is a mix-up of ANSI and Unicode strings. The result is probably a Unicode string in the following form.

[tt]M.i.c.r.o.s.o.f.t. .C.o.r.p.o.r.a.t.i.o.n...[/tt]

Note that all '.' characters are null characters. This is a unicode string of 44 bytes, last two null characters signalling the end of string.

If you read the above string as ANSI, you will only get "M" as it is followed by a null character which signals the end of the ANSI string.

Examine your code and make sure you don't read the resultant Unicode string as ANSI string. Or use the ANSI version of VerQueryValue function, which returns the result in ANSI format.
 
Okay, this helped me to find the answer. VerQueryValue always seems to return a unicode capable string, so I needed to convert the unicode string to something my programming language would display.

Thanks for the help!
 
okay, here's the next question: These files I had a trouble with would only return unicode strings no matter what verqueryvalue I'd call (A or W). Now I notice making the change I did broke the ones encoded in ANSI. So now do I need to make a unicode string detection routine, or is there something I can read within the version info that'll tell me what kind of string to expect?
 
Can you give the example of two kinds of executables present in Windows XP so that I examine the version info and test the code myself?

Which language you are coding in?
 
OK I figured it out with some research. Basically a MSI executable (basically Microsoft Software Installer) is an OLE encapsulated file, which by Microsoft's definition always returns a unicode string from VerQueryValueA/W no matter what. Nice inconsistent standard, no?

So ultimately I have to run the W variants no matter what. I figured that out after I squashed a small bug I had in my string definitions.

Moral of the story I guess is to always use the W variants of functions when interacting with the operating system.

I gave an example of one of these MSI execs, the .NET SP1 867460 patch, though anything .NET will work and is basically common.

Thanks again for the help.
 
FYI, the W versions didn't work on one of my platforms I wanted to support (and I couldn't get MSLU to work right, either, there really needs to be some better documentation on it), so I wrote a Unicode string detection function (basically check length, report true if more than one null - not sure if it will work everywhere, but it's suitable for what I'm testing on).

The problem is now solved :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top