It depends on the type of the registry value that you are requesting. If it's a DWORD value, lpData should be a pointer to a DWORD. If it's a string, lpData should specify a TCHAR array. If it's binary, lpData should specify a BYTE array. You will need to use a cast for this argument. Here are a couple of functions that demonstrate.
Code:
// =====================================================================================
HRESULT RegGetString(HKEY hKey, LPCTSTR szValueName, LPTSTR * lpszResult) {
// Given a HKEY and value name returns a string from the registry.
// Upon successful return the string should be freed using free()
// eg. RegGetString(hKey, TEXT("my value"), &szString);
DWORD dwType=0, dwDataSize=0, dwBufSize=0;
LONG lResult;
// Incase we fail set the return string to null...
if (lpszResult != NULL) *lpszResult = NULL;
// Check input parameters...
if (hKey == NULL || lpszResult == NULL) return E_INVALIDARG;
// Get the length of the string in bytes (placed in dwDataSize)...
lResult = RegQueryValueEx(hKey, szValueName, 0, &dwType, NULL, &dwDataSize );
// Check result and make sure the registry value is a string(REG_SZ)...
if (lResult != ERROR_SUCCESS) return HRESULT_FROM_WIN32(lResult);
else if (dwType != REG_SZ) return DISP_E_TYPEMISMATCH;
// Allocate memory for string - We add space for a null terminating character...
dwBufSize = dwDataSize + (1 * sizeof(TCHAR));
*lpszResult = malloc(dwBufSize);
if (*lpszResult == NULL) return E_OUTOFMEMORY;
// Now get the actual string from the registry...
lResult = RegQueryValueEx(hKey, szValueName, 0, &dwType, (LPBYTE) *lpszResult, &dwDataSize );
// Check result and type again.
// If we fail here we must free the memory we allocated...
if (lResult != ERROR_SUCCESS) { free(*lpszResult); return HRESULT_FROM_WIN32(lResult); }
else if (dwType != REG_SZ) { free(*lpszResult); return DISP_E_TYPEMISMATCH; }
// We are not guaranteed a null terminated string from RegQueryValueEx.
// Explicitly null terminate the returned string...
(*lpszResult)[(dwBufSize / sizeof(TCHAR)) - 1] = TEXT('\0');
return NOERROR;
}
// =====================================================================================
HRESULT RegGetDWord(HKEY hKey, LPCTSTR szValueName, DWORD * lpdwResult) {
// Given a value name and an hKey returns a DWORD from the registry.
// eg. RegGetDWord(hKey, TEXT("my dword"), &dwMyValue);
LONG lResult;
DWORD dwDataSize = sizeof(DWORD);
DWORD dwType = 0;
// Check input parameters...
if (hKey == NULL || lpdwResult == NULL) return E_INVALIDARG;
// Get dword value from the registry...
lResult = RegQueryValueEx(hKey, szValueName, 0, &dwType, (LPBYTE) lpdwResult, &dwDataSize );
// Check result and make sure the registry value is a DWORD(REG_DWORD)...
if (lResult != ERROR_SUCCESS) return HRESULT_FROM_WIN32(lResult);
else if (dwType != REG_DWORD) return DISP_E_TYPEMISMATCH;
return NOERROR;
}