[PATCH v4 2/8] reg.exe: Add path_get_key() to remove boilerplate
Ken Thomases
ken at codeweavers.com
Sun Oct 12 11:38:57 CDT 2014
On Oct 12, 2014, at 11:11 AM, Stefan Dösinger <stefandoesinger at gmail.com> wrote:
> Am 2014-10-12 15:58, schrieb Stefan Dösinger:
>> Something like
>> static const struct
>> {
>> HKEY key;
>> const WCHAR *long_name;
>> const WCHAR *short_name;
>> }
>> keys[] =
>> {
>> {HKEY_LOCAL_MACHINE, {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0}, {'H','K','L','M',0}},
>> ...
>> };
> As Jonathan pointed out in a private message this does not work. Is there a canonical way to handle this? All solutions I found are somewhat ugly or I'm not sure if they are correct.
It should work to make the long_name and short_name fields arrays instead of pointers, although that brings back the use of fixed lengths.
The other approach is to define the strings like:
static const WCHAR short_name_HKLM[] = {'H','K','L','M',0};
…
static const WCHAR long_name_HKEY_LOCAL_MACHINE[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
…
and then build the table as:
static const struct
{
HKEY key;
const WCHAR *long_name;
const WCHAR *short_name;
}
keys[] =
{
{HKEY_LOCAL_MACHINE, long_name_HKEY_LOCAL_MACHINE, short_name_HKLM},
…
};
That's not especially compact, but at least it makes a single table and avoids fixed-length arrays.
Regards,
Ken
More information about the wine-devel
mailing list