Getting error 87 (INVALID_PARAMETER) when executing RegGetValueA

581 Views Asked by At

My code:

HKEY hKey;
char *path = "SYSTEM\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles\\0001";
LONG result1 = RegOpenKeyExA(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS, &hKey);
QString q = QString::number(result1);

if (result1 == ERROR_SUCCESS) {
    LPDWORD b {};
    char *buffer[250];
    LONG result12 = RegGetValueA(hKey, path, "HwProfileGuid", RRF_RT_REG_SZ, NULL, &buffer, b);

    if (result12 == ERROR_SUCCESS) {

        QMessageBox messageBox1;
        messageBox1.critical(0,"Error", "Sucesso");
        messageBox1.setFixedSize(500,200);
    } else {
        QString q = QString::number(result12);
        QMessageBox messageBox2;
        messageBox2.critical(0,"Error", q);
        messageBox2.setFixedSize(500,200);
    }


} else {
    QMessageBox messageBox2;
    messageBox2.critical(0,"Error", q);
    messageBox2.setFixedSize(500,200);
}

I am a beginner and I am unsure of what parameter is the invalid one.

1

There are 1 best solutions below

3
On

RegGetValueA function (winreg.h) - Win32 apps | Microsoft Docs says:

The pcbData parameter can be NULL only if pvData is NULL.

Your pvData is &buffer, which won't be NULL, but your pcbData is b, which is initialized to NULL. Therefore this condition is not satisfied.

Also there looks like more errors:

  • The parameter should be a pointer where the length of buffer passed to pvData is stored.
  • It looks weird to use an array of pointer as the buffer to receive the data.
  • the key to read is already specified for RegOpenKeyExA, so you shouldn't specify that for RegGetValueA again. Otherwise, it will try to read the path under the path (SYSTEM\...\0001\SYSTEM\...\0001).

The part

LPDWORD b {};
char *buffer[250];
LONG result12 = RegGetValueA(hKey, NULL, "HwProfileGuid", RRF_RT_REG_SZ, NULL, &buffer, b);

should be

char buffer[250];
DWORD b = sizeof(buffer);
LONG result12 = RegGetValueA(hKey, path, "HwProfileGuid", RRF_RT_REG_SZ, NULL, buffer, &b);