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?
sbondalapatiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Emmanuel PASQUIERFreelance Project ManagerCommented:
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
Emmanuel PASQUIERFreelance Project ManagerCommented:
can you specify which error do you get ?
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sbondalapatiAuthor Commented:
find the image
Sans-titre.png
0
Emmanuel PASQUIERFreelance Project ManagerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.