`productKey.end() - 1` could be done instead of `--productKey.end()`. But I don't think that ought to be done; `str` will be missing the last character (if `productKey` is not null-terminated).

Since `productKey` may or may not be null-terminated (and it may even have more than 1 trailing `'\0'`), I might suggest decrementing `keyNameSize` until the string is no-longer null-terminated. Also, note that `std::string` may be the wrong type. `TCHAR` may be `char` or `wchar_t`, which means `str` should be a `std::basic_string<TCHAR>`. I would suggest changing/adding the following:

```
std::vector<TCHAR> productKey(keyNameSize / sizeof(TCHAR));
result = RegQueryValueEx(currentKey, REGSTR_VAL_JOYOEMNAME, NULL, NULL, (LPBYTE) &productKey[0], &keyNameSize);

while (keyNameSize > 0 && productKey[keyNameSize - 1] == 0)
{
    --keyNameSize;
 }

if (result == ERROR_SUCCESS)
{
    joystickDescription = std::basic_string<TCHAR>(&productKey[0], keyNameSize);
}
```