[python-win32] AddObject from C
dzzie
dzzie at yahoo.com
Sun Sep 17 16:44:34 EDT 2023
Seems to be solved:
------------------------------------------------------------------------------------
/lib/site-packages/pycom/__init__.py
def GetObject(Pathname=None, Class=None, clsctx=None):
...if Class is not None:
return GetActiveObject(Class, clsctx)
else:
#first check to see if its an in process COM object shared from VB before we check ROT
v = pycomint.HostResolver(Pathname);
#print(type(v)) #<class 'PyIDispatch'> or <class 'NoneType'>
if v is not None:
return __WrapDispatch(v, Pathname, clsctx=clsctx)
else:
return Moniker(Pathname, clsctx)
------------------------------------------------------------------------------------
PythonCOM.cpp
static PyObject *pythoncom_HostResolver(PyObject *self, PyObject *args)
{
int rv = 0;
char* s;
if(vbHostResolver == NULL) return Py_BuildValue("");
if (!PyArg_ParseTuple(args, "s", &s)) return Py_BuildValue("");
//PY_INTERFACE_PRECALL;
rv = vbHostResolver(s, 0, 0, 0);
//PY_INTERFACE_POSTCALL;
if (rv == 0) return Py_BuildValue("");
return PyCom_PyObjectFromIUnknown((IUnknown*)rv, IID_IDispatch, FALSE);
}
---------------------------------------------------------------------------------------
VB6 implementation
Public Function HostResolver(ByVal buf As Long, ByVal v1 As Long, ByVal v2 As Long, ByVal v3 As Long) As Long
On Error Resume Next
Dim key As String
Dim o As Object
key = LCase(StringFromPointer(buf))
Set o = SharedObjects(key)
If Not o Is Nothing Then
HostResolver = ObjPtr(o)
Else
HostResolver = 0
End If
End Function
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20230917/43dfc0b5/attachment.html>
More information about the python-win32
mailing list