The project needs to read the value of the next subkey of the HKEY_CLASSES_ROOT primary key in the registry, looking at the instructions for MSDN, with RegOpenKeyEx and RegQueryValueEx Two functions can be used. Without carefully reading the function description, I wrote a simple code to test:
HKEY HKEY; WCHAR Szlocation[max_path] = {' REG_SZ '};D Word dwsize = sizeof;D word dwtype LPCTSTR Studiopath = TEXT ("Insta360\\studio"); LONG Ret;ret = RegOpenKeyEx (HKEY_CLASSES_ROOT, Studiopath, 0, Key_read, &hkey); wprintf (L "RegOpenKeyEx returns%d\n" , ret), if (error_success = = ret) {ret = RegQueryValueEx (HKey, TEXT ("Install_location"), 0, &dwtype, (LPBYTE) &szlo cation, &dwsize); wprintf (L "RegQueryValueEx returns%d, dwsize=%d\n", ret, dwsize); if (error_success = = ret) {wprintf (L "Location:%s", szlocation);} RegCloseKey (HKey);}
A run to discover what also did not read out, and RegQueryValueEx () unexpectedly return is 234 (error_more_data), suddenly a face Meng force.
The key is that the last parameter of the function. The type is labeled [In][out]. In other words, this parameter is both the input of the function and the output of the function . The function will be in this parameter when it reads the registry with the amount of space that is actually needed. The user allocates the required memory space based on this size. So the program can call this function to test the size before it is formally read:
Note that the second-to-last argument to this function should pass NULL when tempted. But in fact it can not be tempted. Instead, set the input value of the last parameter a bit larger so that the 234 error code is not returned.
Reference links
Https://www.experts-exchange.com/questions/23897919/RegQueryValueEx-causes-Error-234.html
RegQueryValueEx Correct use method