Link to home
Create AccountLog in
Avatar of ChrisMDrew
ChrisMDrew

asked on

Ensure CString has no non-printing characters before write to XML

Hi,

I have a program which is recovering various bits of information about files and folders by reading the VERSIONINFO using GetFileVersionInfo.  While this works in the main, occasionally the string returned has non-printing characters as its last digit - most often 0x1 and 0x3.  After scanning many thousands of files I found 3 which had corrupt strings.

My problem is that I am writing this data to an XML file which becomes invalid with these non-printing characters.

What I would like is a method by which I can remove these non-printing characters and/or format the string so that it will always be valid within an XML file.

The CString::Trim functions don't seem to catch this and I have not been able to find an alternate method of doing this efficiently.  Any suggestions?
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

You have to retrieve the values by using VerQueryValue prior to calling GetFileVersionInfoSize and GetFileVersionInfo. These are the keywords you could ask for with VerQueryValue:

Comments
InternalName
ProductName
CompanyName
LegalCopyright
ProductVersion
FileDescription
LegalTrademarks
PrivateBuild
FileVersion
OriginalFilename
SpecialBuild

You can pass more than one key by separating with backslash \ .

The output of VerQueryValue is an array of pointers of type void** and the pointers were pointing into the version info resource you have to provide as first argument.
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account