Converting 32bit application to 64bit

-1

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!!

c++
winapi
mfc
64-bit
ulong
asked on Stack Overflow Oct 27, 2020 by Sandeep Kumar • edited Oct 27, 2020 by Asesh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0