I have used the following piece of code for registering HKCR (this required admin privileges, not sure about HKLM) using regserver32 on a dll. But believe this can work from a regular c++ program. Hope it helps!
HRESULT SetHKLMRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName,
PCWSTR pszData)
{
HRESULT hr;
HKEY hKey = NULL;
hr = HRESULT_FROM_WIN32(RegCreateKeyEx(HKEY_LOCAL_MACHINE, pszSubKey, 0,
NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
if (SUCCEEDED(hr))
{
if (pszData != NULL)
{
DWORD cbData = lstrlen(pszData) * sizeof(*pszData);
hr = HRESULT_FROM_WIN32(RegSetValueEx(hKey, pszValueName, 0,
REG_SZ, reinterpret_cast<const BYTE *>(pszData), cbData));
}
RegCloseKey(hKey);
}
return hr;
}