Can't Find Namespace "Microsoft.Win32"

97 Views Asked by At

I'm running the latest version of Visual Studio C++ desktop with the latest v4.8.04084 version of .NET Framework, and in a header file I have #include <Windows.h> followed later by "using Microsoft.Win32". Here "Microsoft" gets the red squiggly underline. Without the Microsoft prefix, "Win32" also gets the red squiggly line. "identifier "Microsoft" is undefined, etc.

Evidently, Visual Studio can't find where these two are defined. Please note that "Windows.h" shows up in the project's "External Dependencies" list. It would appear, then, that the missing identifiers are not defined in Windows.h or in winreg.h, which is included in Windows.h. Having spent days trying to find the files in which these identifiers are defined, I am at a loss.

My aim is to be able to edit values in the registry. Does anyone know where the identifiers "Microsoft", "Win32", and "Microsoft.Win32" are defined?

I tried many searches on the Internet for answers to this question. Chat GPT said that these identifiers should be defined in winreg.h. No such luck.

Also, no luck with Visual Studio 2017.

1

There are 1 best solutions below

0
user22487671 On

For anyone else programming in C++ for Windows and wishing to read and write values in the registry, here is the answer. As pointed out by the helpful commenters, we have to ignore the C# and .NET information regarding winreg.h. This resource is completely different in C#/.NET from the winreg.h file for C++. The former may define a Microsoft.Win32 namespace. The latter does not.

I was able to read and write time-format registry values in the HKEY_CURRENT_USER\Control Panel\International subkey by using the C functions RegOpenKeyExA (with KEY_QUERY_VALUE | KEY_SET_VALUE as the samDesired parameter value), RegGetValueA, RegSetValueExA, and RegCloseKey, all of which are declared in the winreg.h file installed by the Visual Studio 2022 C++ Community version. In using the functions it was necessary to adhere strictly to some arcane type names such as HKEY, DWORD, LSTATUS, and BYTE and to allocate and free some buffer space with the malloc and free functions. It works.

The winreg.h overview at https://learn.microsoft.com/en-us/windows/win32/api/winreg/ and its links were sufficient for learning how to use the C functions.