0

I am trying to use a method present in an ocx file.

The definition of this method is (resolution from VS - c#) VS Screen

[DispId(17)]
[MethodImpl(MethodImplOptions.PreserveSig | MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int EcrCmd([MarshalAs(UnmanagedType.BStr)] string Command, [MarshalAs(UnmanagedType.BStr)] ref string pResult);

My Python code

self.frame = wx.Frame(parent=None, id=wx.ID_ANY,size=(500,500), title='Python Interface to COECRCOM')
self.gd = wx.lib.activex.ActiveXCtrl(self.frame, "COECRCOM.CoEcrComCtrl.1")
status = self.gd.ctrl.Status
print(status)

error = ""
cmd = self.gd.ctrl.EcrCmd("nofis apri", error)
print(cmd)
print(error)

access to self.gd.ctrl.Status is fine.

I can't pass the right type of parameters to the self.gd.ctrl.EcrCmd method

Traceback (most recent call last):
  File "...lib\site-packages\comtypes\automation.py", line 855, in Invoke
    byref(result), byref(excepinfo), byref(argerr))
_ctypes.COMError: (-2147352571, 'Type incompatibility.', (None, None, None, 0, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File main.py", line 31, in <module>
    app = MainApp()
  File "main.py", line 20, in __init__
    cmd = self.gd.ctrl.EcrCmd("nofis apri", error)
  File "...lib\site-packages\comtypes\_memberspec.py", line 448, in func
    return obj.Invoke(memid, _invkind=1, *args, **kw) # DISPATCH_METHOD
  File "...lib\site-packages\comtypes\automation.py", line 878, in Invoke
    args))
_ctypes.COMError: (-2147352571, 'Type incompatibility.', ('TypeError: Parameter 1', ('nofis apri', '')))
  • env: 32bit (win-32)
  • python: 3.7.13
  • comtypes: v1.2.1
  • wxpython: 4.0.4

1 Answer 1

0

Solved

import comtypes
from _ctypes import pointer
...

error = pointer(comtypes.BSTR())
cmd = self.gd.ctrl.EcrCmd("nofis apri", error)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.