[PATCH v3 01/17] shell32/autocomplete: Revamp pwzsRegKeyPath handling so it can deal with arbitrary sizes and make it more robust
Huw Davies
huw at codeweavers.com
Thu Sep 6 09:08:08 CDT 2018
On Thu, Sep 06, 2018 at 04:31:04PM +0300, Gabriel Ivăncescu wrote:
> >
> > This try_HKLM thing is ugly. I'd suggest having a outer loop over the two registry
> > root keys (HKCU and HKLM) which tries to access the supplied key / value. If the
> > access succeeds then break out of the loop.
> >
> I'm afraid I don't understand how to do it that way without
> duplicating the RegQueryValue part of the code.
>
> The problem is that even if the key exists under HKCU, the value might
> not. This means RegQueryValueEx would fail, even though the key itself
> is open under HKCU. But then I have to retry under HKLM. Which means I
> would have to duplicate the RegQueryValueEx at least twice (if not 3
> times) just to see if the value exists first. And then have to keep it
> in the real loop until the buffer is satisfied. Originally I had
> "duplicated" this with just getting the size initially, but Alexandre
> told me to get the string right away with a reasonable size (here
> MAX_PATH like the original code) so I had to devise this ugly BOOL
> thing to reduce the amount of code duplication and keep it to a
> minimum.
>
> Any rough sketches of how it's supposed to be done without duplicating
> the code? Or should I duplicate it?
Well something like:
HKEY roots[] = {HKCU, HKLM};
int i;
for (i = 0; i < ARRAY_SIZE(roots); i++)
{
if (RegOpenKeyEx(roots[i], key, ..., &hkey) == ERROR_SUCCESS)
{
ret = query_value(hkey, value);
RegCloseKey(hkey);
if (ret == ERROR_SUCCESS)
{
This->quick_complete = data;
break;
}
}
}
where query_value does the appropriate calls to RegQueryValueEx().
Huw.
More information about the wine-devel
mailing list