Guest User

Untitled

a guest
Jan 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. int GetRegistryStringValue(HKEY h_sub_key, WCHAR* value_name, wstring *result)
  2. {
  3. DWORD cbData = 8;
  4. Debug *debug = Debug::GetInstance();
  5.  
  6. LPDWORD type = NULL;
  7.  
  8. //Get the size and type of the key
  9. int err = RegQueryValueEx(h_sub_key, value_name, NULL, type, NULL, &cbData);
  10.  
  11. if (err != ERROR_SUCCESS)
  12. {
  13. debug->DebugMessage(Error::GetErrorMessageW(err));
  14. return err;
  15. }
  16.  
  17. result->resize(cbData / sizeof(WCHAR));
  18.  
  19. LPWSTR res = new WCHAR[(cbData + sizeof(L'\0')) / sizeof(WCHAR)];
  20.  
  21. err = RegQueryValueEx(h_sub_key, value_name, NULL, NULL, (LPBYTE) &res[0], &cbData);
  22.  
  23. if(err != ERROR_SUCCESS)
  24. {
  25. debug->DebugMessage(Error::GetErrorMessageW(err));
  26. return err;
  27. }
  28.  
  29. res[cbData / sizeof(WCHAR)] = L'\0';
  30.  
  31. result = new wstring(res);
  32.  
  33. return ERROR_SUCCESS;
  34. }
Add Comment
Please, Sign In to add comment