Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-07

WinCE and version

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antonio Fortuny

Hi All.
Does anyone know whether it is possible to save (at compile time) and extract (at runtime) the program version in WinCE as I use it currently in Win32 and Win64 ?
It appears that the same code doesn't work. There is the code snippet I use:

function ReadVersionInfo(const sProgram: string; Out vv: PTVersion)
:Boolean;
var
   Info:       PVSFixedFileInfo;
   InfoSize:   Cardinal;
   nHwnd:      DWORD;
   BufferSize: DWORD;
   Buffer:     Pointer;
begin
   ZeroMemory(Info, SizeOF(PVSFixedFileInfo));
   vv := new(PTVersion);
   InfoSize := 0;
   nHwnd := 0;
   with vv^ do begin
     Major:= -1;
     Minor := 0;
     Release := 0;
     Build := 0;
   end;
   Result := False; //no version info at all in the file
   BufferSize := GetFileVersionInfoSize(pchar(sProgram), nHWnd); {Get
buffer size}
   if BufferSize  0 then begin //if zero, there is no version info
     Buffer := nil;
     ReAllocMem(Buffer, BufferSize+1);
     try
       if GetFileVersionInfo(PChar(sProgram),nHWnd,BufferSize,Buffer)
then begin  // got version info
         if VerQueryValue(Buffer, PChar('\'), Pointer(Info), InfoSize)
then begin   //got root block version information
           with vv^ do begin
             Major := HiWord(Info^.dwFileVersionMS); //extract major version
             Minor := LoWord(Info^.dwFileVersionMS); //extract minor version
             Release := HiWord(Info^.dwFileVersionLS); //extract release
version
             Build := LoWord(Info^.dwFileVersionLS); //extract build version
           end;
           Result := True;
         end
       end
     finally
       ReAllocMem(Buffer, 0);
     end
   end;
end;

Thanks,
Antonio.

Reply by email

Antonio Fortuny
to Ludo Brands

Le 03/07/2012 17:17, Ludo Brands a ?crit :

> BufferSize := GetFileVersionInfoSize(pchar(sProgram), nHWnd); {Get All WinCE API functions are the W unicode versions. So GetFileVersionInfoSize takes a pointer to widechar.
I've omitted that there is some conditional code as
{$IFDEF WINCE}
   BufferSize := GetFileVersionInfoSize(PWideChar(sProgram),nHWnd); {Get
buffer size}
   AddLog(Format('WinCE buffersize:%d', [BufferSize]));
{$ELSE}
   BufferSize := GetFileVersionInfoSize(PChar(sProgram),nHWnd); {Get
buffer size}
   AddLog(Format('Win32 buffersize:%d', [BufferSize]));
{$ENDIF}
It works with Win32 but WinCE gives always 0 (zero). Maybe one o f those
numerous unimplemented features ?
Show quoted text 10 lines
Ludo -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Tommi Prami
to Antonio Fortuny: Hi All. Does anyone know whether it is possible to save (at compile time) and extract (at…

Hello,

I'm also interested in this, if someone gets this to work... Hope working codde is posted into the list :)

-Tee-

Antonio Fortuny wrote 66 lines
Hi All. Does anyone know whether it is possible to save (at compile time) and extract (at runtime) the program version in WinCE as I use it currently in Win32 and Win64 ? It appears that the same code doesn't work. There is the code snippet I use: function ReadVersionInfo(const sProgram: string; Out vv: PTVersion) :Boolean; var Info: PVSFixedFileInfo; InfoSize: Cardinal; nHwnd: DWORD; BufferSize: DWORD; Buffer: Pointer; begin ZeroMemory(Info, SizeOF(PVSFixedFileInfo)); vv := new(PTVersion); InfoSize := 0; nHwnd := 0; with vv^ do begin Major:= -1; Minor := 0; Release := 0; Build := 0; end; Result := False; //no version info at all in the file BufferSize := GetFileVersionInfoSize(pchar(sProgram), nHWnd); {Get buffer size} if BufferSize 0 then begin //if zero, there is no version info Buffer := nil; ReAllocMem(Buffer, BufferSize+1); try if GetFileVersionInfo(PChar(sProgram),nHWnd,BufferSize,Buffer) then begin // got version info if VerQueryValue(Buffer, PChar('\'), Pointer(Info), InfoSize) then begin //got root block version information with vv^ do begin Major := HiWord(Info^.dwFileVersionMS); //extract major version Minor := LoWord(Info^.dwFileVersionMS); //extract minor version Release := HiWord(Info^.dwFileVersionLS); //extract release version Build := LoWord(Info^.dwFileVersionLS); //extract build version end; Result := True; end end finally ReAllocMem(Buffer, 0); end end; end; Thanks, Antonio. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Felipe Monteiro de Carvalho
to Antonio Fortuny: Le 03/07/2012 17:17, Ludo Brands a ?crit : I've omitted that there is some conditional…
Antonio Fortuny wrote 6 lines
I've omitted that there is some conditional code as {$IFDEF WINCE} BufferSize := GetFileVersionInfoSize(PWideChar(sProgram),nHWnd); {Get buffer size} AddLog(Format('WinCE buffersize:%d', [BufferSize])); {$ELSE}

Did you notice that you are type-casting a string to a PWideChar? Maybe the compiler does special hidden conversions to make this work, but I would not be so reliant on hidden behaviors.

If I were you I would do it like this:

var
  wProgram: widestring;
begin
  wProgram := UTF8ToUTF16(sProgram); // or whatever other desired
conversion routine
 {$IFDEF WINCE}
   BufferSize := GetFileVersionInfoSize(PWideChar(wProgram),nHWnd);
Felipe Monteiro de Carvalho

Reply by email

Ludo Brands
to Felipe Monteiro de Carvalho
Show quoted text 6 lines
Did you notice that you are type-casting a string to a PWideChar? Maybe the compiler does special hidden conversions to make this work, but I would not be so reliant on hidden behaviors. If I were you I would do it like this:

Unit winceproc has a GetFileVersion that could be easily expanded to give build and release number.

Replacing PChar(sProgram) with PWideChar(UTF8Decode(sProgram) in Antonio's code works also. Tested on a WinCE 5.0 device.

Ludo

Reply by email

Antonio Fortuny
to Ludo Brands

Le 04/07/2012 14:02, Ludo Brands a ?crit :

Show quoted text 11 lines
> Did you notice that you are type-casting a string to a > PWideChar? Maybe the compiler does special hidden conversions > to make this work, but I would not be so reliant on hidden behaviors. > > If I were you I would do it like this: > Unit winceproc has a GetFileVersion that could be easily expanded to give build and release number. Replacing PChar(sProgram) with PWideChar(UTF8Decode(sProgram) in Antonio's code works also. Tested on a WinCE 5.0 device.

You are absolutely right, it works
Thanks

Antonio.

Show quoted text 10 lines
Ludo -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email