HI friends,
i need to create a subkey in windows registry and write some data also i need to access the data which i write...Plz send me the code with the header files or namespace which i have to include...i am working in vc++.net (unmanaged applications)...Plz help me...thanks in advance...sherin

Dani AI

Generated

: here's a compact, practical pattern for VC++ (unmanaged) that creates a subkey under HKEY_CURRENT_USER, writes a string and a DWORD, then reads them back. It builds on the Win32 registry APIs that pointed toward and the tutorial suggestion from , but shows a minimal working example and the key caveats you’ll hit in real projects.

#include <windows.h>
#include <tchar.h>
#include <cstdio>

int main()
{
    HKEY hKey = NULL;
    const TCHAR* path = _T("Software\\MyCompany\\MyApp");
    LONG rc = RegCreateKeyEx(HKEY_CURRENT_USER, path, 0, NULL,
                             REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
                             NULL, &hKey, NULL);
    if (rc != ERROR_SUCCESS) return 1;

    const TCHAR* text = _T("HelloRegistry");
    rc = RegSetValueEx(hKey, _T("Greeting"), 0, REG_SZ,
                       (const BYTE*)text, (lstrlen(text) + 1) * sizeof(TCHAR));

    DWORD num = 123;
    rc = RegSetValueEx(hKey, _T("Count"), 0, REG_DWORD,
                       (const BYTE*)&num, sizeof(num));

    TCHAR buf[256];
    DWORD bufLen = sizeof(buf);
    DWORD type = 0;
    rc = RegQueryValueEx(hKey, _T("Greeting"), NULL, &type, (LPBYTE)buf, &bufLen);
    if (rc == ERROR_SUCCESS && type == REG_SZ) _tprintf(_T("Greeting=%s\n"), buf);

    DWORD out = 0; DWORD outLen = sizeof(out);
    rc = RegQueryValueEx(hKey, _T("Count"), NULL, &type, (LPBYTE)&out, &outLen);
    if (rc == ERROR_SUCCESS && type == REG_DWORD) _tprintf(_T("Count=%u\n"), out);

    RegCloseKey(hKey);
    return 0;
}

Notes and tips:

  • Include <windows.h> and <tchar.h>. Link with Advapi32.lib (registry APIs live in advapi32).
  • Use HKEY_CURRENT_USER for per-user settings; HKEY_LOCAL_MACHINE needs admin rights.
  • For 64-bit OS concerns, 32-bit apps are redirected to Wow6432Node unless you pass KEY_WOW64_64KEY or KEY_WOW64_32KEY in samDesired.
  • Always check return codes (ERROR_SUCCESS). Use correct byte lengths: strings use (lstrlen+1)*sizeof(TCHAR); DWORD uses sizeof(DWORD).
  • Don’t store secrets in plain text. Consider proper encryption or protected storage for sensitive data.
    This should get the basic create/write/read loop working in an unmanaged VC++ project.

Recommended Answers

All 4 Replies

Can u provide sample code plzzzz

Can u provide sample code plzzzz

Read the bottom link. It has example code, read it yourself.

There are a few tutorials, such as this one (click here)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.