"More data available" error on RegQueryValueEx: but buffer not too small 
Author Message
 "More data available" error on RegQueryValueEx: but buffer not too small

I get a "More data available" error for the following code, which tries to
read a REG_SZ value set to "Joe Blow".  After the RegQueryValueEx call,
miscSize is 9, which is correct, but tmpStr is unchanged.

DWORD miscSize;
TCHAR tmpStr[32];
HRESULT retVal
retVal = RegQueryValueEx(miscKey,
    TEXT("userProfile"),
    0,
    NULL,
    (LPBYTE)tmpStr,
    &miscSize);

This code is taken almost exactly from the Platform SDK Docs' "Retrieving
Data from the Registry," and I can't figure out what the problem is.

--
Jeff S.



Tue, 28 Jun 2005 01:48:22 GMT  
 "More data available" error on RegQueryValueEx: but buffer not too small
http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&sa...
threadm=01bd4943%24a01fff90%2426275f8b%40cqbp1&rnum=4&prev=/groups%3Fq%3D%25
22More%2Bdata%2Bis%2Bavailable%2522%2Bregqueryvalueex%26hl%3Den%26lr%3Dlang_
en%26ie%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26selm%3D01bd4943%2524a01fff90%252
426275f8b%2540cqbp1%26rnum%3D4

solved my problem.  Turns out the docs don't tell you that the last
parameter is read to determine whether the buffer is big enough.  *groan*.

--
Jeff S.


Quote:
> I get a "More data available" error for the following code, which tries to
> read a REG_SZ value set to "Joe Blow".  After the RegQueryValueEx call,
> miscSize is 9, which is correct, but tmpStr is unchanged.

> DWORD miscSize;
> TCHAR tmpStr[32];
> HRESULT retVal
> retVal = RegQueryValueEx(miscKey,
>     TEXT("userProfile"),
>     0,
>     NULL,
>     (LPBYTE)tmpStr,
>     &miscSize);

> This code is taken almost exactly from the Platform SDK Docs' "Retrieving
> Data from the Registry," and I can't figure out what the problem is.

> --
> Jeff S.



Tue, 28 Jun 2005 01:52:45 GMT  
 "More data available" error on RegQueryValueEx: but buffer not too small


Quote:
>I get a "More data available" error for the following code, which tries to
>read a REG_SZ value set to "Joe Blow".  After the RegQueryValueEx call,
>miscSize is 9, which is correct, but tmpStr is unchanged.

>DWORD miscSize;
>TCHAR tmpStr[32];
>HRESULT retVal
>retVal = RegQueryValueEx(miscKey,
>    TEXT("userProfile"),
>    0,
>    NULL,
>    (LPBYTE)tmpStr,
>    &miscSize);

>This code is taken almost exactly from the Platform SDK Docs' "Retrieving
>Data from the Registry," and I can't figure out what the problem is.

From the RegQueryValueEx() documentation:

"lpcbData [in, out] Pointer to a variable that specifies the size of the
buffer pointed to by the lpData parameter, in bytes. When the function
returns, this variable contains the size of the data copied to lpData."

You need to initialize "miscSize" with the size of your buffer.  If you get
into the habit of *always* initializing your variables you will reduce the
number of times you get bitten by this type of thing.

Further, RegQueryValueEx() returns a LONG, not an HRESULT.

Try this version instead:

TCHAR tmpStr[32] = { '\0' };
DWORD miscSize = sizeof(tmpStr);  //buffer size in *bytes* not characters
LONG retVal = RegQueryValueEx(miscKey,
                              TEXT("userProfile"),
                              NULL,
                              NULL,
                              reinterpret_cast<LPBYTE>(tmpStr),
                              &miscSize);

Jon



Tue, 28 Jun 2005 03:25:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CObList and "operator= not available" error

2. "time.h" is not available

3. "Unable to Create File Buffer" error

4. Displaying binary data as ascii "1"'s and "0"'s

5. Displaying binary data as ascii "1"'s and "0"'s

6. "Data source not found" message

7. Error "free"-ing "malloc"-ed memory

8. "C# does not support Data Breakpoints"

9. Error when "==" is in data

10. "DATA ERROR IN DRIVE C" **URGENT**

11. ODBC Error - "Restricted data type attribute violation", code 07006

12. "Unavailable data base" Error

 

 
Powered by phpBB® Forum Software