[python-win32] AddObject from C

2023-09-19 Thread dzzie via python-win32
Hi guys
I am working with an embedded interpreter, how can I share an existing COM 
object from the C api ?(without using the ROT)

Background:
The host process is VB6 with a C helper DLL.
I have stripped down the pywin32 library to compile directly into my helper dll 
with just the COM access features.
Right now I can createobject() and getobject() in python using the new 
namespaces.

Experimenting with using this for app automation similar to the microsoft 
script control and its addobject functionality.
Bringing the COM code into my helper dll to see if I can get around not being 
able to call PyFinalize with the full library.




___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] AddObject from C

2023-09-19 Thread dzzie via python-win32
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)) # or 
    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
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] VB6 Listbox methods fail through ROT

2023-10-04 Thread dzzie via python-win32
 Wondering if anyone might have an insight on this.
If we add a vb6 listbox to the ROT, and try to access it using GetObjectwe can 
not access any of its methods with an error "Member not found"
 import win32com.client

form1 = win32com.client.GetObject('PyComTest.Form1')
form1.caption = "hi from vb!!"  # works
#form1.Move(0) #pywintypes.com_error: (-2147352573, 'Member not found.', None, 
None)

List1 = win32com.client.GetObject('PyComTest.List1')
#List1.AddItem('') #pywintypes.com_error: (-2147352573, 
'Member not found.', None, None)
List1.Clear() #pywintypes.com_error: (-2147352573, 'Member not found.', None, 
None)
--
as a sanity check both do work from vb script
Set form1 = GetObject("PyComTest.Form1")
form1.caption = "test"
form1.Move(0)

Set List1 = GetObject("PyComTest.List1")
List1.AddItem "* VBS SAYS HELLO ***"
Currently using a vb6 standard exe manually adding objects to the ROT, and 
python 311 exe to run the scripts externally. 
I have not yet tried with a vb6 activex exe. 
Most things do work like textboxes, form methods etc. 
  ___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32