[python-win32] Help creating simple COM example

Niki Spahiev niki@vintech.bg
Thu, 04 Apr 2002 11:32:05 +0300


Jim Vickroy wrote:
> I am unable to properly create and use a simple COM server.
> 
> Here is the script:
> 
> class PyCOMtest_3:
>    _public_methods_ = ['hits']
>    _reg_progid_ = 'PyCOM.Test3'
>    _reg_clsid_ = '{F7F5808C-7280-4545-9F88-8DC2A395D039}'
>    current_value = 0
> 
>    def hits(self):
>       self.current_value += 1
>       return self.current_value
> 
> if __name__ == '__main__':
>    import win32com.server.register
>    win32com.server.register.UseCommandLine(PyCOMtest_3)
> 
> 
> Now, here is an interactive session after registering it:
> 
> 
>>>>Registered: PyCOM.Test3
>>>>pct = win32com.client.Dispatch('PyCOM.Test3')
>>>
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "C:\Python22\lib\site-packages\win32com\client\__init__.py", line
> 92, in Dispatch
>     dispatch, userName =
> dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>   File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line
> 81, in _GetGoodDispatchAndUserName
>     return (_GetGoodDispatch(IDispatch, clsctx), userName)
>   File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line
> 72, in _GetGoodDispatch
>     IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
> com_error: (-2147221231, 'ClassFactory cannot supply requested class',
> None, None)
> 
> 
> What am I doing that is incorrect?
> 
You can't test python com server from same python process.

Niki Spahiev