Unicode style in win32/PythonWin

Thomas Heller theller at python.net
Thu Jan 12 04:33:48 EST 2006


"Robert" <kxroberto at googlemail.com> writes:

> Neil Hodgson wrote:
>> Robert:
>>
>> > After "is_platform_unicode = <auto>", scintilla displays some unicode
>> > as you showed. but the win32-functions (e.g. MessageBox) still do not
>> > pass through wide unicode.
>>
>>     Win32 issues are better discussed on the python-win32 mailing list
>> which is read by more of the people interested in working on this library.
>> http://mail.python.org/mailman/listinfo/python-win32
>>     Patches that improve MessageBox in particular or larger sets of
>> functions in a general way are likely to be welcomed.
>
> ok. I have no patches so far as of now - maybe later. Played with
> Heller's ctypes for my urgent needs. That works correct with unicode
> like this:
>
>>>> import ctypes
>>>> ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043a.txt',0,0)
> 1

FYI, if you assign the argtypes attribute for ctypes functions, the
ascii/unicode conversion is automatic (if needed).

So after these assignments:

  ctypes.windll.user32.MessageBoxW.argtypes = (c_int, c_wchar_p,
                                               c_wchar_p, c_int)
  ctypes.windll.user32.MessageBoxA.argtypes = (c_int, c_char_p,
                                               c_char_p, c_int)

both MessageBoxA and MessageBoxW can both be called with either ansi and
unicode strings, and should work correctly.  By default the conversion
is done with ('msbc', 'ignore'), but this can also be changed,
ctypes-wide, with a call to ctypes.set_conversion_mode(encoding,errors).

You have to pass None for the third parameter (if not a string).

Thomas



More information about the Python-list mailing list