Is there a concrete way to determine the exact buffer size required for a REG_BINARY value for RegQueryValueEx in C? If possible, please provide code demonstrating method.
Is there a concrete way to determine the exact buffer size required for a
Share
Do the winAPI double-call dance, which applies to numerous win APIs besides the
Regfunctions: callRegQueryValueExonce, passing NULL aslpData, and a pointer tolpcpData, args 5 and 6. The function will returnERROR_SUCCESSand filllpcpDatawith the required buffer size. Call again with a buffer of that size.You can also begin with passing a buffer, and if it’s too small the function will return
ERROR_MORE_DATAand filllpcpDatawith the required buffer size.Consider the following general pseudo-code for a winapi loop which employs the second approach:
This also handles cases where the buffer might change size between calls, i.e. a shared buffer or a registry key that’s being updated.