MSDN解释
LONG RegQueryValueEx(
HKEY hKey,
LPCTSTR lpValueName,
LPDWORD lpReserved,
LPDWORD lpType,
LPBYTE lpData,
LPDWORD lpcbData
);
the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to bylpcbData. In this case, the contents of the lpData buffer are undefined.
If lpData is NULL, and lpcbData is non-NULL, the function returns ERROR_SUCCESS and stores the size of the data, in bytes, in the variable pointed to bylpcbData. This enables an application to determine the best way to allocate a buffer for the value's data.
char* buffer = NULL;
DWORD dwBytes=0;
DWORD dwType;
DWORD dwRet;
dwRet = RegQueryValueExA(hKey, "...", NULL, &dwType, NULL, &dwBytes);
if (ERROR_SUCCESS == dwRet)
{
buffer = (char*)malloc(dwBytes*sizeof(char));
ZeroMemory(buffer,sizeof(buffer));
dwRet = RegQueryValueExA(hKey, "...", NULL, &dwType, (LPBYTE)buffer, &dwBytes);
if(ERROR_SUCCESS !=dwRet )
free(buffer);
}
当使用RegQueryValueEx时,如果缓冲区太小,函数会返回ERROR_MORE_DATA并提供所需大小。如果lpData为NULL,lpcbData非NULL,函数会返回ERROR_SUCCESS并给出数据的大小。
635

被折叠的 条评论
为什么被折叠?



