I am trying to convert a 32 bit application to 64bit (using VS2019). Following is the code I am using to open a registrykey
CString strSection;
HKEY hKey;
bool bOK((RegOpenKeyEx(HKEY_CURRENT_USER, strSection, 0, KEY_READ, &hKey) == ERROR_SUCCESS));
When I compile the above code in 64 bit, I get the following warning
"warning C4312: 'type cast': conversion from 'ULONG' to 'HKEY' of greater size".
I understand that the warning is related to the first argument that we passed to RegOpenKeyEx function.
When I see the definition of HKEY_CURRENT_USER
, it is defined as
#define HKEY_CURRENT_USER (( HKEY ) (ULONG_PTR)((LONG)0x80000001) ) in winreg.h
From the above line I see a LONG
value is type casted to ULONG_PTR
and then to HKEY
but the warning shows
as "conversion from 'ULONG' to 'HKEY' of greater size"
what could be the reason, Also can we fix the warning.
Thanks!!
User contributions licensed under CC BY-SA 3.0