Creating a Registry Value in C++/CLI environment
-
I was wondering if anybody could give me hand solving this problem. I need to save a DWORD value (DesiredValue) in a registry key and this was the syntax I was using (successfully) in console environment.
DWORD DesiredValue;
// Creates Desired Registry Key
HKEY Xtmpkey;
DWORD dwDisp = 0;
LPDWORD xlpdwDisposition = &dwDisp;
DWORD dwVal = DesiredValue;
// Desired Path for the Registry Key
RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\MyPath", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &Xtmpkey,xlpdwDisposition);// Creates Desired Value
RegSetValueEx (Xtmpkey, L"Desired_Value_Name", 0L, REG_DWORD,(CONST BYTE*) &dwVal, sizeof(DWORD));Now that I am porting the software into C++/CLI environment it returns the following errors: Error 1 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES * const,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKQAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) Error 2 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegSetValueExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExW@@$$J224YGJPAUHKEY__@@PB_WKKPBEK@Z) Error 3 fatal error LNK1120: 2 unresolved externals What am I doing wrong? Thanks in advance.
-
I was wondering if anybody could give me hand solving this problem. I need to save a DWORD value (DesiredValue) in a registry key and this was the syntax I was using (successfully) in console environment.
DWORD DesiredValue;
// Creates Desired Registry Key
HKEY Xtmpkey;
DWORD dwDisp = 0;
LPDWORD xlpdwDisposition = &dwDisp;
DWORD dwVal = DesiredValue;
// Desired Path for the Registry Key
RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\MyPath", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &Xtmpkey,xlpdwDisposition);// Creates Desired Value
RegSetValueEx (Xtmpkey, L"Desired_Value_Name", 0L, REG_DWORD,(CONST BYTE*) &dwVal, sizeof(DWORD));Now that I am porting the software into C++/CLI environment it returns the following errors: Error 1 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES * const,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKQAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) Error 2 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegSetValueExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExW@@$$J224YGJPAUHKEY__@@PB_WKKPBEK@Z) Error 3 fatal error LNK1120: 2 unresolved externals What am I doing wrong? Thanks in advance.
You need to link to Advapi32.lib. #pragma comment(lib, "Advapi32.lib") Or, since it's managed code, you could use the Microsoft.Win32.Registry Class[^], which is a tad easier to use than the Win32 APIs. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You need to link to Advapi32.lib. #pragma comment(lib, "Advapi32.lib") Or, since it's managed code, you could use the Microsoft.Win32.Registry Class[^], which is a tad easier to use than the Win32 APIs. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery wrote:
You need to link to Advapi32.lib. #pragma comment(lib, "Advapi32.lib")
You are a "C"enius, it works! I wish one day I could be as smart. :-D
:laugh: It's all in the documentation ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I was wondering if anybody could give me hand solving this problem. I need to save a DWORD value (DesiredValue) in a registry key and this was the syntax I was using (successfully) in console environment.
DWORD DesiredValue;
// Creates Desired Registry Key
HKEY Xtmpkey;
DWORD dwDisp = 0;
LPDWORD xlpdwDisposition = &dwDisp;
DWORD dwVal = DesiredValue;
// Desired Path for the Registry Key
RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\MyPath", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &Xtmpkey,xlpdwDisposition);// Creates Desired Value
RegSetValueEx (Xtmpkey, L"Desired_Value_Name", 0L, REG_DWORD,(CONST BYTE*) &dwVal, sizeof(DWORD));Now that I am porting the software into C++/CLI environment it returns the following errors: Error 1 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES * const,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKQAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) Error 2 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegSetValueExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExW@@$$J224YGJPAUHKEY__@@PB_WKKPBEK@Z) Error 3 fatal error LNK1120: 2 unresolved externals What am I doing wrong? Thanks in advance.