How to check a registry's data?

How can I check the content of the registry key I have created?

I have tried using "RegQueryValueKeyEx"
but can seems to work. Registry is not updated..

Any idea why?
Who is Participating?
xutaoConnect With a Mentor Commented:
The RegSetValueEx function sets the data and type of a specified value under a registry key.

LONG RegSetValueEx(
  HKEY hKey,           // handle to key
  LPCTSTR lpValueName, // value name
  DWORD Reserved,      // reserved
  DWORD dwType,        // value type
  CONST BYTE *lpData,  // value data
  DWORD cbData         // size of value data

The RegQueryValueEx function retrieves the type and data for a specified value name associated with an open registry key.

LONG RegQueryValueEx(
  HKEY hKey,            // handle to key
  LPCTSTR lpValueName,  // value name
  LPDWORD lpReserved,   // reserved
  LPDWORD lpType,       // type buffer
  LPBYTE lpData,        // data buffer
  LPDWORD lpcbData      // size of data buffer

And check the return value when you open or create a registry key.Notice: if you use null-terminated string containing the name of the subkey, double slash(\\) is needed.
Please paste the code that you use to access the registry, or how can we know what happen.
raymondweeAuthor Commented:
My test application for registry manipulation is as attached below. Some of those codes are for debugging purposes.

                HKEY hKeyResult = 0;
      HKEY hKey = 0;
      DWORD dwDisposition = 0;
      char initial_value[2] = "0";
      char Reg_value[10] = "";
      DWORD Value = 0;
      DWORD value = 0;
      long CreateResult = RegCreateKeyEx(HKEY_CLASSES_ROOT,"Test",0,"",REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKeyResult,&dwDisposition);
if(CreateResult != ERROR_SUCCESS)

      long OpenResult = RegOpenKeyEx(HKEY_CLASSES_ROOT,"Test",0,KEY_QUERY_VALUE,&hKey);

      long SetResult = RegSetValue(hKeyResult,NULL,REG_SZ,"8",1);


      value = atol(Reg_value) + 1;

      SetResult = RegSetValue(hKeyResult,NULL,REG_SZ,Reg_value,1);

      if(SetResult != ERROR_SUCCESS)

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Add Value = sizeof(Reg_value) before RegQueryValueEx.
long SetResult = RegSetValue(hKeyResult,NULL,REG_SZ,"8",1);

//////// Add this

Value = sizeof(Reg_value);


you'd better check the return value of RegQueryValueEx, it can tell why the function failed.
raymondweeAuthor Commented:
Thanks xutao and yz for your answers.

I can update the registry now.

yz, why does it work if the Value = sizeof(....) is added before the Query...

Pls email me at

Thanks again.
Paste a part of the description of the RegQueryValueEx from MSDN below.
[in/out] Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the lpData parameter. When the function returns, this variable contains the size of the data copied to lpData.
notice the variable lpcbData is [in/out], it means you should give is a exectly value when call the function, if need, the function will give you back a new value.
raymondweeAuthor Commented:
thx again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.