Andrew Talbot wrote:
Robert Shearman wrote:
This is incorrect. count is the size in bytes of the buffer passed in (szName) and so should be sizeof(szName) not sizeof(szName)/sizeof(szName[0]) (i.e. 80).
Are you sure? MSDN says "szName: Array of 80 Unicode characters that receives the name of the DMO".
It doesn't matter what MSDN says about szName, RegQueryValueExW still takes the size in bytes, not characters. I.e. count should be set to NAME_SIZE * sizeof(WCHAR), not NAME_SIZE.
But, in any case, when arrays are passed as arguments to functions they are converted to pointers, so sizeof(szName) would represent the size of a pointer to the array, not the size of the array itself.
I didn't realise this before but the attached test program prints: $ ./atest sizeof(array) = 4 So you are right. Still, my point stands that the code is still passing in a smaller size than the size of the buffer and so is not correct.