Retrive unicode keys from the registry

Neil Hodgson nhodgson at bigpond.net.au
Fri Jan 16 16:59:30 EST 2004


Thomas Heller:

> In the actual use case I have, I'm quite sure that the subkeys are coded
> in latin-1:

   And you are also sure that your locale will always use a latin-1 code
page or another code page similar enough to work on your keys.

> But, assume that I wanted to provide a patch to Python (or implement in
> ctypes) so that QueryValue accepts unicode subkey names (I was
> astonished to find out that it does not).  How could this be done,
> hopefully portable between NT/2000/XP and 98, and assuming unicows.dll
> is not installed - so the wide version is not available on 98?

   This is somewhat unpleasant, requiring runtime conditional code. For the
Python standard library, in posixmodule.c, places where there is a need to
branch first check that the OS is capable of wide calls with
unicode_file_names(), then check if the argument is Unicode and if it is
then it calls the wide system API. While the wide APIs do not work on 9x,
they are present so the executable will still load.

   One limitation on the Unicode support in posixmodule is that it doesn't
try to detect and use MSLU on Windows 9x/Me.

> My understanding is that it's possible to convert any (for a certain
> definition of 'any) unicode string in a byte string (because the
> encoding for the byte string can be specified).

   Then you have to choose the encoding and switch the current locale to
that encoding as there is no encoding or locale parameter to RegQueryValue.
Values with characters from different languages may not be encodable into
any non-Unicode encoding.

   Neil





More information about the Python-list mailing list