how to register COM interface from python COM-server

Konstantin Pilkevich pilkevitch at gmx.net
Tue Apr 23 09:54:41 EDT 2002


hi all

i got a problem using Python COM server. 
I have working python COM-server Dictionary Singleton (updated
dictionary, you can find 3  .py-files attached). I wrote idl file for
it. It was compliled by midl withour errors. I've got type lib file
and registered it. After that i created C++ class from type lib file
from VC++ Class Wizard. And it works normally with server.
 
The problem is that i can't use this solution, because in this case i
must use MFC, and i should not.
 
I tried to use this server in such way:
 
 CoInitialize(NULL);
 IMainDictionary *pDict;
 IDispatch *pDisp;
 _GUID guid;
 CLSIDFromProgID(L"Python.DictionarySng",&guid);
 long res = 0;
 IClassFactory *unk = NULL;
 
 res = CoCreateInstance(guid,NULL,CLSCTX_ALL,IID_IDispatch,(void**)&pDisp);
 if(res==S_OK && pDisp != NULL)
 {
  pDisp->AddRef();
  res = pDisp->QueryInterface(IID_IMainDictionary,(void**)&pDict);
 }
 else if(res==E_NOINTERFACE)
 {
  return 0;
 }

instance of object was created normally but QueryInterface failed.
i added such code to server:
 
IID_IMainDictionary =
pythoncom.MakeIID("{B5B94B7D-A76F-47b4-B755-EDCA4F5A5925}")

and overload query_interface function:
  def _query_interface_(self, iid):
      if iid==IID_IMainDictionary:
        return win32com.server.util.wrap(self)

but needed interface is still not supported.
can you help me to find the way to register my interface.



More information about the Python-list mailing list