[python-win32] Making a COM server that accepts COM objects

Boylan, Ross Ross.Boylan at ucsf.edu
Fri Jan 11 17:43:37 EST 2019


I changed to an InProcess server, which doesn't seem to work any better or worse than the LocalServer.  Here's the trace:
---------------------------------------------------------------------------------------------------
Object with win32trace dispatcher created (object=None)
in <BSTImport.BSTImport object at 0x0712EED0>._QueryInterface_ with unsupported IID b'IPersistStreamInit' ({7FD52380-4E07-101B-AE2D-08002B2EC713})
in <BSTImport.BSTImport object at 0x0712EED0>._QueryInterface_ with unsupported IID b'IPersistPropertyBag' ({37D84F60-42CB-11CE-8135-00AA004BB851})
in _GetIDsOfNames_ with '('Barney',)' and '1033'

in _Invoke_ with 1001 1033 3 (<PyIDispatch at 0x087036D8 with obj at 0x085D79B0>, <PyIDispatch at 0x087036C0 with obj at 0x085D9356>)
Traceback (most recent call last):
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_
    return self.policy._Invoke_(dispid, lcid, wFlags, args)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 278, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 283, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 586, in _invokeex_
    return func(*args)
  File "C:\Users\rdboylan\Documents\Wk devel\BSTImport.py", line 37, in Barney
    rst = fedb.OpenRecordset("foo")
AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset'
pythoncom error: Python error invoking COM method.

Traceback (most recent call last):
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 163, in _Invoke_
    return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 49, in _Invoke_
    return self._HandleException_()
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_
    return self.policy._Invoke_(dispid, lcid, wFlags, args)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 278, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 283, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Users\rdboylan\AppData\Roaming\Python\Python37\site-packages\win32com\server\policy.py", line 586, in _invokeex_
    return func(*args)
  File "C:\Users\rdboylan\Documents\Wk devel\BSTImport.py", line 37, in Barney
    rst = fedb.OpenRecordset("foo")
AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset'
---------------------------------------------------

To try to ensure that the old LocalServer wasn't active I did --unregister first, and restarted the calling program after that.

I first tried commenting out
    #_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
when that didn't work I renamed the registry key LocalServer32 (I think; it's gone now) to NoLocalServer32.  when that didn't work I set
    _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER
and did the unregister/register, verifying there was no reference to the local server in the registry after.

Ross

________________________________________
From: python-win32 <python-win32-bounces+ross.boylan=ucsf.edu at python.org> on behalf of Tim Roberts <timr at probo.com>
Sent: Wednesday, January 9, 2019 10:05:53 AM
To: Python-Win32 List
Subject: Re: [python-win32] Making a COM server that accepts COM objects

Boylan, Ross wrote:
> I have a Python 3.7, 32 bit, COM server and am calling it from 32 bit Office 2010 in VBA.  I am attempting to pass some COM objects from VBA to Python.  The trace collector full output appears below, but I think the key clues are several messages like
>
> in <BSTImport.BSTImport object at 0x009F62F0>._QueryInterface_ with unsupported IID {00000003-0000-0000-C000-000000000046} ({00000003-0000-0000-C000-000000000046})

Those are not important.  The COM framework is just probing to find out
what extras you support.  00000003-etc is IMarshal and 0000001B-etc is
IStandardMarshal; both can be used to help in the RPC process.


> and, later,
>      rst = fedb.OpenRecordset("foo")
> AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset'

You can't just pass an Access database object to another process and
expect it to work.  The support pieces aren't there.  Thus, the crux of
your problem is this:

>      _reg_progid_ = "Fahy.BST"
>      # for unknown reasons the inprocess server isn't working
>      _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER

That's the problem you need to chase.  You need to be an in-process
server if you want to share state with the original code.  What happens
when you register yourself as in-process? Note that the registry has to
look different for this.

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.




More information about the python-win32 mailing list