registrykey - C++ Why does my code put a registry key at the wrong directory? -


so, want put registry key @ directory hkcu\software\microsoft\windows\currentversion\run, , want called test, , have contain "testtext", instead code puts new key @ hkcu\test , program writes random chinese characters in registry key. help?

#include "stdafx.h" #include <iostream> #include <windows.h> #include <string> #include <time.h> using namespace std;  int main() {      hkey keyexample;      if (regopenkey(hkey_current_user, text("software\\microsoft\\windows\\currentversion\\run\\"), &keyexample) != error_success)     {         regclosekey(keyexample);         return 69;     }      if (regsetkeyvalue(hkey_current_user, text("test"), 0, reg_sz, (lpbyte)"testtext", strlen("testtext")*sizeof(char)) != error_success)      {          regclosekey(keyexample);          cout << "unable set registry value value_name";      }       regclosekey(keyexample);      return 0; } 

regsetkeyvalue(hkey_current_user, ... 

this bug. need use keyexample got when opened key wanted. this:

regsetkeyvalue(keyexample, ... 

and ansi/unicode problem, need use text() macro actual data, not name:

regsetkeyvalue(keyexample, text("test"), 0, reg_sz, text("testtext"), lstrlen(text("testtext"))*sizeof(tchar)) 

it's easier forget legacy backward compatible stuff related text/tchar menus , directly call w versions of windows api functions long strings.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -