Re: AddObject from C
dzzie via python-win32 <[email protected]> Sun, 17 Sep 2023 20:44:34 +0000 (UTC)
| Newsgroups | gmane.comp.python.windows |
|---|---|
| Message-ID | <[email protected]> |
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
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32