August 29, 2008

Why did the RegQueryValueEx() return ERROR_MORE_DATA?

Q: Why does the RegQueryValueEx() always return ERROR_MORE_DATA?

A: If the lpData buffer is too small to receive the data, the function returns ERROR_MORE_DATA.

Windows API:

LONG WINAPI RegQueryValueEx(
  __in HKEY hKey,
  __in_opt LPCTSTR lpValueName,
  __reserved LPDWORD lpReserved,
  __out_opt LPDWORD lpType,
  __out_opt LPBYTE lpData,
  __inout_opt LPDWORD lpcbData

When you are using RegQueryValueExW(), the parameter of lpcbData
SHOULD be the array size in BYTES, not in characters.

MSDN Reference: