c - Error 234, more data is available, with RegQueryInfoKey and RegEnumValue -


i trying use regqueryinfokey longest value , data´s size , regenumvalue show values, getting 234 error value, means "more data available" when run app.

i using malloc allocate lpvaluename , lpdata can use sizes regqueryinfokey gave me.

if set lpcchvaluename 16383, example, app works fine, no idea why doesn't lpcmaxsubkeylen value returned regqueryinfokey.

the registry key has 2 string values: hkcu\winside string values

what doing wrong? apologize noob errors might see. here code:

int wmain() {     //regopenkeyex     hkey hkey = hkey_current_user;     lpcwstr subkey = l"winside";     dword options = 0;     regsam samdesired = key_query_value;     hkey hkopenresult;      //opening hkey_current_user\winside subkey     long openkey = regopenkeyex(hkey, subkey, options,                             samdesired, &hkopenresult);      if (openkey != error_success)         wprintf(l"error code: %li\n", openkey);     else     {         wprintf(l"key opened!\n");          //regqueryinfokey         lpwstr pclass = null;         lpdword pcclass = null;         lpdword reserved = null;         dword numberofsubkeys;         lpdword pcmaxsubkeylen = null;         lpdword pcmaxclasslen = null;         dword numberofvalues;         dword longestvaluename;         dword longestdatacomponent;         lpdword securitydescriptor = null;         pfiletime plastwritetime = null;          //querying info hkcu\winside subkey         long queryinfo = regqueryinfokey(hkopenresult, pclass, pcclass, reserved, &numberofsubkeys,                                         pcmaxsubkeylen, pcmaxclasslen, &numberofvalues,                                         &longestvaluename, &longestdatacomponent,                                         securitydescriptor, plastwritetime);          if (queryinfo != error_success)             wprintf(l"error code: %li\n", queryinfo);         else         {             wprintf(l"key queried!\n");             wprintf(l"number of values: %u\n", numberofvalues);              //regenumvalue             dword index=0;             dword sizedem = sizeof(wchar);             lpwstr nameofvalue = (lpwstr)malloc(longestvaluename * sizeof(wchar));             dword sizeofbufffer = longestvaluename;             dword typeofdatastored;             lpbyte pdata = (lpbyte)malloc(longestdatacomponent * sizeof(byte));             dword sizeofdata = longestdatacomponent;              if (nameofvalue != null && pdata != null)             {                 (index = 0; index < numberofvalues; index++)                 {                     sizeofbufffer = longestvaluename;                      //enumerating values hkcu\winside subkey                     long enuvalue = regenumvalue(hkopenresult, index, nameofvalue,                         &sizeofbufffer, null, &typeofdatastored,                         pdata, &sizeofdata);                      if (enuvalue != error_success)                         wprintf(l"error code: %li\n", enuvalue);                     else                     {                         wprintf(l"value: %s\n", (lpwstr)pdata);                      }                  }              }             else             {                 wprintf(l"memory not allocated.\n");             }                       free(nameofvalue);             free(pdata);           }            regclosekey(hkopenresult);     }      return 0;  } 

this result:

result

thanks lot!

your code containing many errors.

1) lpwstr nameofvalue = (lpwstr)malloc(longestvaluename * sizeof(wchar));

really longestvaluename

the size not include terminating null character.

so need

lpwstr nameofvalue = (lpwstr)malloc((longestvaluename + 1) * sizeof(wchar)); 

or (better)

lpwstr nameofvalue = (lpwstr)malloc(++longestvaluename * sizeof(wchar)); 

then in loop, if use first variant - sizeofbufffer = longestvaluename + 1;

or in code, if use ++longestvaluename

2) dword sizeofdata = longestdatacomponent;

you must in loop, , sizeofbufffer = longestvaluename; because sizeofdata changed after every regenumvalue

3) , must ready, until enumerate key, can change key data/values - maximum can increase - got in call regqueryinfokey reasonable hint not 100% guarantee


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -