[Tutor] how can I use the functions inside ITfInputProcessorProfiles

Tim Golden mail at timgolden.me.uk
Fri Jul 11 18:00:45 CEST 2008

Dror Cohen wrote:
> I'm trying to use the these functions which are in isnide of 
> ITfInputProcessorProfiles
> http://msdn.microsoft.com/en-us/library/ms538984(VS.85).aspx
> I think that its registry key is {892F230F-FE00-4A41-A98E-FCD6DE0D35EF} 
> (though I don't know if I even need this)
> How can I use its function inside of python.
> I tried using this by thinking it will get me somewhere (Got no idea if 
> I was even close)
> point = None
> Inputpp = pythoncom.MakeIID('{892F230F-FE00-4A41-A98E-FCD6DE0D35EF}')
> pythoncom.CoCreateInstance(Inputpp, None, 
> pythoncom.CLSCTX_INPROC_SERVER, point)
> but then I got this error message
>  Traceback (most recent call last):
>    File "<interactive input>", line 1, in <module>
>     TypeError: Only strings and iids can be converted to a CLSID.

This question would probably be better posed to the python-win32
mailing list. People on the tutor list are always ready to be helpful,
but this one's a bit specific.

To answer your question as straightforwardly as possible: the
pywin32 COM extensions can't handle arbitrary COM interfaces.
For that you need to use comtypes [1] (or write your own extension).
The code below works against the current comtypes svn HEAD.

import ctypes
from ctypes import wintypes
import comtypes

class ITfInputProcessorProfiles  (comtypes.IUnknown):
  _iid_ = comtypes.GUID ("{1F02B6C5-7842-4EE6-8A0B-9A24183A95CA}")
  _idlflags_ = []
  _case_insensitive_ = False
  _methods_ = [
    comtypes.COMMETHOD (
      [], comtypes.HRESULT, "GetCurrentLanguage",
      (["out"], ctypes.POINTER (wintypes.LANGID), "pLangId")

ipp = comtypes.CoCreateInstance (
  comtypes.IID ("{33C53A50-F456-4884-B049-85FD643ECFED}"),

langid = wintypes.LANGID (ipp.GetCurrentLanguage ())
print langid


I get a value of 0, which seems to indicate a major and sub language
of NEUTRAL. I don't really know how languages work on Windows,
and there seem to be too many variants. As an alternative, you
might want to look at the win32api module, which has functions
like GetUserDefaultLangID and GetUserDefaultLCID.


[1] http://starship.python.net/crew/theller/comtypes/

More information about the Tutor mailing list