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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Version Info 3

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
0
0
GB
I have been using a component that fills an array from the version info, but after installing in new Delphi, it doesn't seem to be picking up the line feeds (or whatever the separator is), so each entry contains part of the next etc. Anyone know what this might be?

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
That was my guess. The help still suggests using the getversioninfo API, this is what is embedded in the component. Is the problem is at that level?

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
I tried looking up "GetVersionInfo" and didn't find a specific MSDN page, and found a lot of .NET references. Is this the name of the call or is it something else?

The way this is sounding though it is a Unicode vs. ANSI strings issue. For all Win32 API calls where it matters, there's an A version and a W version. You got to be sure to call the W version if you are using WideStrings.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Glenn: Wrote that on my laptop..
here is the API call in the component

GetFileVersionInfo(a,0,struSize,p);

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Hover over reveals this:-
WINDOWS.GetFileVersionInfo(PWideChar, Cardinal, Cardinal, Pointer) Method

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
you will see that GetFileVersionInfo is routed to the GetFileVersionInfoW function which is indeed unicode.
if you have the sourcode of the component just change GetFileVersionInfo call to GetFileVersionInfoA
->

Code:
 GetFileVersionInfo(a,0,struSize,p);

or change the component so that it takes unicode into account.

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
That looks good, Changed to the A version but a bit more for me to do....

[DCC Error] getver.pas(141): E2010 Incompatible types: 'PAnsiChar' and 'array[0..256] of Char'

where...
Code:
var struSize : Dword;
    dwBytes,someDummy : Dword;
    a,txt : array[0..256] of char;
......................
// and (where FFileName is a string)
 strPCopy(a,FFileName);

......................
// and
 GetFileVersionInfoA(a,0,struSize,p);

need a version of str_copy that converts to ansii? or can I just pass the string ?


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
hmm. strPCopy is overloaded, so I created an ansichar and used strpcopy to copy ffilename to that, result, nasty access violation.

heres a bit more of the code (after my changes)

Code:
procedure TGetVersionInfoFromFile.readVersionFromFile;
var struSize : Dword;
    dwBytes,someDummy : Dword;
    a,txt : array[0..256] of char;
    pAc: PansiChar; // my addition
    p : pchar;
    i : integer;
    pp : pointer;
    theFixedInfo : TVSFixedFileInfo;
    theTrans : TTranslation;
    s : string;
    ts  : TStringList;
begin
     ts := TStringList.Create;
     ts.add('CompanyName');
     ts.add('FileDescription');
     ts.add('FileVersion');
     ts.add('InternalName');
     ts.add('LegalCopyright');
     ts.add('OriginalFilename');
     ts.add('ProductName');
     ts.add('ProductVersion');

     strPCopy(a,FFileName);
     strPCopy(pAc, FFileName); // my addition crash propgates from here
     { get size of data }
     struSize := GetFileVersionInfoSize(a,someDummy);
     if struSize=0 then exit;
     p := NIL;
     try
       { get memory }
       GetMem(p,struSize+10);
       { get data }
       GetFileVersionInfoA(pAc, 0, struSize,p); // now using the A version with ansii char variable.

       { get root info }
       if not VerQueryValue(p,'\',pp,dwBytes) then exit;
       move(pp^,theFixedInfo,dwBytes);

       { get translation info }
       if not VerQueryValue(p,'\VarFileInfo\Translation',pp,dwBytes) then exit;
       move(pp^,theTrans,dwBytes);

       { iterate over defined items }
       for i:=0 to ts.count-1 do
       begin
         s := '\StringFileInfo\'+inttohex(theTrans.langID,4)+inttohex(theTrans.charset,4)+'\'+ts[i];
         StrPCopy(a,s);
         if not VerQueryValue(p,a,pp,dwBytes) then exit;

         if dwBytes>0 then
         begin
          move(pp^,txt,dwBytes);
          FmyVersionCategories.add(ts[i]);
          FmyVersionStrings.add(StrPas(txt));
         end;
       end;
     finally
       { release memory }
       FreeMem(p);
     end;
end;


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
just change Char to AnsiChar.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
And use the A variant of VerQueryValue



It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Also needed to use GetFileVersionInfoSizeA.

Compiles and runs OK now cheers guys.
A lot of warnings though.
a is now ansichar..

strPCopy(a,FFileName);
[DCC Warning] getver.pas(132): W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString'

and
StrPCopy(a, s);
[DCC Warning] getver.pas(157): W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString'

FmyVersionStrings.add(StrPas(txt));
[DCC Warning] getver.pas(164): W1057 Implicit string cast from 'AnsiString' to 'string'

There is also stuff like 'Time' is depreciated, but no suggestions as to what to use instead?

Now to run QAudit (I dread to think [smile])


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
set AnsiStrings in your uses list and make sure that every string variable is declared as string. that should deal with the warnings.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Did you mean every string declared as AnsiString?

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
yes indeed.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top