RegQueryValueEx返回ERROR_MORE_DATA

来源:互联网 发布:catia汽车设计软件 编辑:程序博客网 时间:2024/05/11 16:05

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 thelpData 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);}


 

 

原创粉丝点击