title: Writing a DWORD value to registry in C++
body: <p>I am trying to write a DWORD value to the registry programmatically in C++.</p>
  
  <p>I've done a bit of searching and I have found that this question has been asked before. I've tried to follow their solution but have come up with a really frustrating issue which, as far as I know, have not been addressed by their solution.</p>
  
  <p>This is my code:</p>
  
  <pre><code>HKEY hKey;
  LPCWSTR sKeyPath;
  int iResult;
  
  sKeyPath = L"Software\\ABI\\";
  iResult = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyPath, NULL, KEY_ALL_ACCESS, &amp;hKey);
  DWORD value = 0x00000003;
  iResult = RegSetValueEx(hKey, L"Test", NULL, REG_DWORD, (const BYTE*)value, sizeof(value));
  RegCloseKey(hKey);
  </code></pre>
  
  <p>I've done some basic debugging and found that the value of <code>iResult</code> is 998 after I call <code>RegSetValueEx</code>. I am sure that this key is present in the windows registry because I created it manually with regedit.exe for testing purposes. The value of the DWORD "Test" is initially 0x00000009 and is unchanged after I run my program.</p>
  
  <p>I am not sure where I am wrong.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>P.S. I've not managed to find any helpful site on the net for error 998. The only reference I found mentions that that's the worst error you can get when handling registry.</p>
  
  <p>P.P.S. By the way, I'm running this program on Windows 8. I don't think that changes anything but I've had experiences with Windows 8 having some weird security issues before.</p>