RTC Forums

Subscription => Support => Topic started by: thomh on December 16, 2022, 01:56:09 PM



Title: Delphi 11.2 OpenSCManager exception
Post by: thomh on December 16, 2022, 01:56:09 PM
Hi,

In Delphi 11.2 Patch 1 compiling in 64bit debug mode, I get an exception in the rtcService unit in method IsServiceStarting on line 44:  SvcMgr := OpenSCManager(nil, nil, SC_MANAGER_CONNECT) and on line 56:  CloseServiceHandle(SvcMgr);

This is running on a Win11 VM with the latest updates.

Can you duplicate this?

Delphi 11.1 works.

// Thom


Title: Re: Delphi 11.2 OpenSCManager exception
Post by: D.Tkalcec (RTC) on December 16, 2022, 02:10:51 PM
OpenSCManager and CloseServiceHandle are both Delphi RTL functions, mapping directly to the Windows API.

I am still on Delphi 11.0 and Windows 10 with no plans to upgrade.

From what I've just read now, Delphi 11.2 has introduced big changes, which might break quite a few things.

Best Regards,
Danijel Tkalcec


Title: Re: Delphi 11.2 OpenSCManager exception
Post by: thomh on December 16, 2022, 03:25:44 PM
Thanks, Danijel.

So back to Delphi 11.1 until EMB fixes this.

// Thom


Title: Re: Delphi 11.2 OpenSCManager exception
Post by: D.Tkalcec (RTC) on December 16, 2022, 11:23:45 PM
Oh, wait. I've just noticed that OpenSCManager and OpenService functions return a THandle (32-bit on 32-bit platforms, 64-bit on 64-bit platforms), but Svc and SvcMgr variables (which store their return values) are declared as Integer (always 32-bit) in the IsServiceStarting function.

This is a bug. Svc and SvcMgs variables should be declared as THandle ...

function IsServiceStarting(const ServiceName:String): Boolean;
  var
    Svc: THandle; // changed from Integer
    SvcMgr: THandle; // changed from Integer
    ServSt: TServiceStatus;

I've committed this fix to GitHub.

Best Regards,
Danijel Tkalcec


Title: Re: Delphi 11.2 OpenSCManager exception
Post by: D.Tkalcec (RTC) on December 17, 2022, 10:53:20 AM
By the way ...

I did install Delphi 11.2 yesterday and found that all the exceptions caused by the new Linker in Delphi 11.2 can be avoided,
if you open Project Options / Building / Delphi Compiler / Linking and remove check-boxes from
   "Support address space layout randomization (ASRL)" and from
   "Support high-entropy 64-bit address space layout randomization (ASLR)".

These settings are per Project and per Target.

Even though I find these new linker options useful for debugging, I would still
recommend anyone who has a Project that needs to run in a Production environment
to DISABLE these two Linker options for their RELEASE / DEPLOYMENT builds.

Best Regards,
Danijel Tkalcec