• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1885
  • Last Modified:

Version.dll problem in delphi 2010 application

HI,

  I developed a delphi application on Delphi 2010 and windows xp 32bit version. It uses the Version.dll to get the version of another exe. When i try to run the same application in Windows 7 64 bit version it is throwing an error some thing like problem with Version.dll. Please tell me how to resolve this?
0
sbondalapati
Asked:
sbondalapati
  • 5
  • 4
1 Solution
 
epasquierCommented:
I don't know about Version.dll, but here is Delphi code to get all file versions you might want

It first declares a type TVersion : version of a file as a record of 4 integer values
Var Version:TVersion;

If you want the TVersion of a file, use
Version:=GetAppVersion('MyApp.Exe');

if you want to convert a TVersion into a string, you can use
Caption:=VersionStr(Version);

GetModuleVersion will do that in one step. if you give it a filename as parameter, it will give you the string version of it. If you don't, or use an empty string parameter (default value), it will return the version of the current module. a module is either the Exe, or the dll, bpl etc .
So easiest way to get the current app version as a string is :
Caption:=GetModuleVersion;

This module file name is get by calling the windows API GetModuleFileName, using the instance number of the module. In all Delphi module, this is a global variable called hInstance .
IF you add this code in a dll or bpl and use it from another application or module, beware that GetModuleVersion will return the version of the dll/bpl where lies this code, not the calling module. To do so, you have to use GetInstanceVersion with hInstance (which will refer to the calling instance)
Caption:=GetInstanceVersion(hInstance);

Type
 TVersion=Record Major,Minor,Release,Build:Integer; end;

Function VersionStr(V:TVersion):String;
begin
 With V do Result:=Format('%d.%d.%d.%d',[Major,Minor,Release,Build]);
 While RightStr(Result,2)='.0' do Result:=LeftStr(Result,Length(Result)-2);
end;

Function GetAppVersion(ExecFile:String=''):TVersion;
var
 Size,Size2: DWord;
 Pt, Pt2: Pointer;
begin
 if ExecFile='' Then ExecFile:=ParamStr(0);
 Size := GetFileVersionInfoSize(PChar (ExecFile), Size2);
 FillChar(Result,Sizeof(Result),0);
 if Size > 0 then
  begin
   GetMem (Pt, Size);
   try
    GetFileVersionInfo (PChar (ExecFile), 0, Size, Pt);
    VerQueryValue (Pt, '\', Pt2, Size);
    with TVSFixedFileInfo (Pt2^),Result do
     begin
      Major:=HiWord (dwFileVersionMS);
      Minor:=LoWord (dwFileVersionMS);
      Release:=HiWord (dwFileVersionLS);
      Build:=LoWord (dwFileVersionLS);
     end;
   finally
     FreeMem (Pt);
   end;
 end;
end;

function GetModuleName(instance:LongWord=0): string;
var
  szFileName: array[0..MAX_PATH] of Char;
begin
  FillChar(szFileName, SizeOf(szFileName), #0);
  if instance=0 Then instance:=hInstance;
  GetModuleFileName(instance, szFileName, MAX_PATH);
  Result := szFileName;
end;

function GetModuleVersion(ModuleName:String=''):String;
begin
 if ModuleName='' Then ModuleName:=GetModuleName;
 Result:=VersionStr(GetAppVersion(ModuleName));
end;

function GetInstanceVersion(Instance:LongWord=0):String;
begin
 Result:=VersionStr(GetAppVersion(GetModuleName(instance)));
end;

Open in new window

0
 
sbondalapatiAuthor Commented:
will this code works with both 32bit os and 64bit os.
0
 
sbondalapatiAuthor Commented:
GetFileVersionInfo (PChar (ExecFile), 0, Size, Pt);
    VerQueryValue (Pt, '\', Pt2, Size);

both the above functions will use version.dll which is platform dependent. if you have any other solution which is platform independent it will be useful.
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
epasquierCommented:
really ? it works for me on Vista64 as well as XP 32
I guess the problem is not 32 or 64 bits, but Windows 7

You are right on one point, it is API of version.dll, I never figured nor cared because it's all transparent in Delphi (it's defined in Windows.pas)

I'll check on MSDN if they say something about this & Seven
0
 
epasquierCommented:
can you specify which error do you get ?
0
 
epasquierCommented:
the code I provided might not work for Delphi 2010 (unicode strings).
Googling a bit, there are also some hints about problems with unicode flavour of the version API, which D2010 will use by default.

That would be worth a try forcing the strings & API to ANSI
Function GetAppVersion(ExecFile:ANSIString=''):TVersion;
var
 Size,Size2: DWord;
 Pt, Pt2: Pointer;
begin
 if ExecFile='' Then ExecFile:=ParamStr(0);
 Size := GetFileVersionInfoSizeA(PANSIChar(ExecFile), Size2);
 FillChar(Result,Sizeof(Result),0);
 if Size > 0 then
  begin
   GetMem (Pt, Size);
   try
    GetFileVersionInfoA (PANSIChar(ExecFile), 0, Size, Pt);
    VerQueryValueA(Pt, '\', Pt2, Size);
    with TVSFixedFileInfo (Pt2^),Result do
     begin
      Major:=HiWord (dwFileVersionMS);
      Minor:=LoWord (dwFileVersionMS);
      Release:=HiWord (dwFileVersionLS);
      Build:=LoWord (dwFileVersionLS);
     end;
   finally
     FreeMem (Pt);
   end;
 end;
end;

Open in new window

0
 
sbondalapatiAuthor Commented:
find the image
Sans-titre.png
0
 
epasquierCommented:
that is a pointer problem. I guess it's a an incompatibility with unicode and/or code compiled with Delphi 2010.
If not done already, can you check with the second version I provided ?

can you trace the exact function call that is throwing this error ?
0
 
sbondalapatiAuthor Commented:
Thanks. Your second version worked perfectly on 2 different types of windows.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now