Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6253033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:54:56+00:00 2026-05-24T13:54:56+00:00

I am trying to get a value which i had set on registry key

  • 0

I am trying to get a value which i had set on registry key “userpath” of type ‘REG_SZ’. Simplified version of code is below.

#include <stdio.h>
#include <windows.h>
#include <iostream>

const static char* SrvKey= "System\\CurrentControlSet\\Services\\LanmanServer\\Parameters";
const static char* sVal = "I am probably \a good boy\0";
const static char* keyName = "userpath";

using namespace std;

int main(int argc, char* argv[]){

    HKEY hkey;
    LONG status;
    DWORD wstatus;
    DWORD dwCtype;
    DWORD dwClen;
    DWORD dwSetStatus;
    status = RegCreateKeyEx(
                HKEY_LOCAL_MACHINE, 
                SrvKey,
                (DWORD) 0,
                NULL,
                REG_OPTION_NON_VOLATILE,
                (KEY_READ | KEY_WRITE),
                NULL,
                &hkey,
                NULL
             );

    if(status != ERROR_SUCCESS){
        printf("Error [%d] on creating key handle\n", status);
        return status;
    }

    //RegFlushKey(hkey);
    dwClen = strlen(sVal);
    dwCtype = REG_SZ;

    dwSetStatus = RegSetValueEx(hkey,
                  keyName,
                  0,
                  dwCtype,
                  (BYTE*)sVal,
                  dwClen);  

    if(dwSetStatus != 0){
                   printf("\nError in setting value in registry. Error [%d]", dwSetStatus);
                   return dwSetStatus;
    }

    RegFlushKey(hkey);

    DWORD dwCheckType = 0;
    DWORD dwCheckLen = 0;
    DWORD dwStatus;
    dwStatus = RegQueryValueEx( hkey,
                               keyName,
                               NULL,
                               &dwCheckType,
                               NULL,
                               &dwCheckLen);
    if(dwStatus != 0){
                printf("\nError in queering registry for length and type. Error [%d]", dwStatus);
                return dwStatus;
    }

    LPBYTE lpbCheckValue = (LPBYTE) malloc(dwCheckLen);

     //dwStatus not check at the moment.
    dwStatus = RegQueryValueEx( hkey,
                                keyName,
                                NULL,
                                &dwCheckType,
                                lpbCheckValue,
                                &dwCheckLen);
    if(dwStatus != 0){
                printf("\nError in queering registry for length and type. Error [%d]", dwStatus);
                return dwStatus;
    }
    printf("queried calue is : [%s]", lpbCheckValue);

    printf("\n\nEndofProgram\n");
    system("PAUSE");
    return 0;
}

I am getting junk value for ‘lpbCheckValue’ after second RegQueryValueE winapi. Please point me what i am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:54:57+00:00Added an answer on May 24, 2026 at 1:54 pm

    What does sizeof(sVal) give? 4? I’m not sure why you’re using wcslen instead of strlen because sVal is a char*, not wchar_t*.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get key-value-observing to work for an NSMutableArray. Below is the
I am trying to compare a value which was grabbed using the get method
Had a headace trying to get this to work, im trying to set up
Trying to get a value out of 2d array inside of a hash and
I am trying to get the value of the text in the input fields.
i am trying to get checkbox value ,using c# In grid view the datasource
I am trying to get the value of a EditText in a dialog box.
i have a label in my form, and im trying to get the value
I'm trying to get an RGB value of a pixel from a CGImageRef object.
I'm trying to get the integer value of The number selected of the item.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.