Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Creating a Registry Value in C++/CLI environment

Creating a Registry Value in C++/CLI environment

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++windows-adminquestionworkspace
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J_E_D_I
    wrote on last edited by
    #1

    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.

    M L 2 Replies Last reply
    0
    • J J_E_D_I

      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.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      J 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        J Offline
        J Offline
        J_E_D_I
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • J J_E_D_I

          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

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          :laugh: It's all in the documentation ;P

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          • J J_E_D_I

            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.

            L Offline
            L Offline
            leonigah
            wrote on last edited by
            #5

            using namespace Microsoft::Win32; Registry::SetValue("HKEY_CURRENT_USER\\SOFTWARE\\MyPath", "Desired_Value_Name", "Value");

            Nigah M Manzoor

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups