Writing string (REG_SZ) values to the registry in C++ -


I have received a lot of code to write a value in the Windows Registry, though when I change the path of a dummy The key and value that I have set up for testing fails. My code is below:

  HKEY hKey; LPCTSTR sk = TEXT ("Software \ TestSoftware"); Long openRes = RegOpenKeyEx (HKEY_LOCAL_MACHINE, SK, 0, KEY_ALL_ACCESS, and HK); If (openRes == ERROR_SUCCESS) {printf ("Success Opening Key."); } Else {printf ("Error opening key."); } LPCTSTR value = TEXT ("TestSoftwareKey"); LPCTR Data = "TestData \ 0"; Long setrs = regatsvaluux (HKE, value, 0, rgigad, (LPBYT) data, strollon (data) +1); If (setRes == ERROR_SUCCESS) {printf ("writing success in the registry."); } Else {printf ("Error writing to the registry."); } Long term = RegCloseKey (hKey); If (closeOut == ERROR_SUCCESS) {printf ("success completion key."); } Else {printf ("Error Closing Key."); }  

All three test yield error conditions.

The part that confuses me is that I was able to run this code while pointing to the other parts of the registry. any idea?

Thank you, Brian

I find silly. The solution is that slash needs to be properly addressed like this:

  LPCTSTR sk = text ("Software \\ TestSoftware");  

Hopefully someone searches for this useful ...


Comments