I need to implement a wrapper class around Winreg.h library.
Problem: All functions work correctly except RegCreateKeyEx, when I try to pass the parameters it returns Error 87.
Example:
When I hardcode the subkey inside the function it works just fine.
HKEY hKey = NULL;
DWORD dc;
int rc = RegCreateKeyEx(HKEY_USERS, L"AppUser\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dc);
But when I parameterized the function like this so I can make the subkey variable and make resursive calls to it it produces Error 87.
HKEY hKey = NULL;
DWORD dc;
const std::wstring szSub = L"AppUser\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
LPCWSTR lpszSub = szSub.c_str();
int rc = RegCreateKeyEx(HKEY_USERS, lpszSub, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dc);
I'm just starting with this library so I don't know what I'm missing, maybe a formatting error or something else. I would appreciate any help or suggestion.