Registry 32 to 64 bit porting

prxy 61 Reputation points
2021-01-21T06:58:34.403+00:00

Hi

We're porting 32bit C++ code to 64bit. The porting of DLL and libs and exe is done and now we're trying change the registry part. Installer has done the changes to create the application related registry key at native hive. In 32bit version, application was accessing the wow6432 hive. Now, I wanted move all registry read/write part to native hive from source code.
While analyzing the code, I found that in many places for RegOpen call we've used KEY_WOW64_32KEY flag, which means access a 32-bit key from either a 32-bit or 64-bit application.
So, my assumption is, I need to remove this flag from all the places so that application(32/64bit version) can always access the native hive.
Is there any other way to do above task efficiently ?
Also, Other than this, Is there any other registry related I should take care while porting registry?

Thank in advance.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,428 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,542 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Petrus 【KIM】 456 Reputation points
    2021-01-25T09:03:53.61+00:00

    IsWow64Process2

    HKEY hRegKey = NULL;

    USHORT nProcessMachine = 0;
    USHORT nNativeMachine = 0;
    DWORD dwSamDesired = KEY_ALL_ACCESS;

    if (IsWow64Process2(GetCurrentProcess(), &nProcessMachine, &nNativeMachine))
    {
    if (nProcessMachine != IMAGE_FILE_MACHINE_UNKNOWN)
    dwSamDesired |= KEY_WOW64_64KEY; //KEY_WOW64_64KEY KEY_WOW64_32KEY
    }

    if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\MICROSOFT\Windows NT\CurrentVersion", REG_OPTION_NON_VOLATILE, dwSamDesired, &hRegKey) == ERROR_SUCCESS)

    0 comments No comments