RegSetValueEx, when passed REG_SZ, needs the length to be in bytes, so don't just use _tcslen like this:
TCHAR sz[] = _T("Hello World");
RegSetValueEx(hKey, bstrValueName, 0, REG_SZ, (const BYTE *)sz, _tcslen(sz));
That truncates the value placed in the registry (11 bytes where it actually needed 24, including the null terminator).
RegSetValueEx, when passed REG_SZ, is documented as needing the length to include the NULL terminator.