Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/WinAPI    [ Add a report in this area ]  
Report #:  100430   Status: Closed
[x64] Registry Rootkeys misdefined in winapi.windows.pas
Project:  Delphi Build #:  16.0.4276.44006
Version:    16.0 Submitted By:   Daniel Terhell
Report Type:  Crash / Data loss / Total failure Date Reported:  10/25/2011 4:39:52 AM
Severity:    Critical / Show Stopper Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   288387
Resolution: Cannot Reproduce (Resolution Comments) Resolved in Build: : latest build
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
[x64]
Registry rootkeys constants are misdefined in
winapi.windows.pas:

HKEY is defined as
  {$EXTERNALSYM HKEY}
  HKEY = type UINT_PTR;

{$EXTERNALSYM HKEY_CLASSES_ROOT}
HKEY_CLASSES_ROOT     = HKEY(Integer($80000000));
etc...

There are three problems with this approach:
*It casts a pointer type to a normal data type
*It casts an UNSIGNED data type to a SIGNED data type
*On 64 bit Windows, it truncates a 64 bit value to 32 bits with data loss

Compiling for 64 bit Windows, the registry rootkey constants are completely misdefined and lost in the conversion. As a result Win32 registry functions are not usable on a 64 bits target.

This is a show stopper for any application which is not aware of the problem that makes use of the registry.

Even on 32 bit I this is dangerous practice and makes no sense.
Steps to Reproduce:
Write a Delphi application that makes use of the registry and compile as a 64 bit Windows target.
Workarounds
Rewrite all code making use of registry rootkey constants with a proper self-defined type. That is without the useless and dangerous conversion to Integer.
Attachment
None
Comments

Tomohiro Takahashi at 1/16/2012 5:56:05 PM -
This is a comment from internal tracking system.
<<<<<<<<<<
We can use registry functions in x64 without an issue...
definition in Visual Studio:
HKEY_LOCAL_MACHINE ((HKEY) (ULONG_PTR)((LONG)0x80000002) )
we:
HKEY_LOCAL_MACHINE    = HKEY(Integer($80000002));
the same value is used in Visual Studio x64 and Delphi x64, no issues with HKEY values.
>>>>>>>>>>

Server Response from: ETNACODE01