Python Forum
How to call COM-method using comtypes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call COM-method using comtypes
#1
I'm using comtypes to call a COM method (with no arguments), however I get an "exception: access violation reading".
When using win32com it Works:
import win32com.client
import pywintypes
result=win32com.client.Dispatch("{9275351B-0F06-366F-A560-933FED81FECF}")
result.AutomationMyType()
Result:
Output:
('text1', 'text2',...,'text99')
When using comtypes it doesn't work:
import comtypes
import comtypes.client as cc
tlb_id = comtypes.GUID("{40B0E4AB-2B70-4142-91A3-839CD72EA140}")
cc.GetModule((tlb_id, 1, 0))
obj=cc.CreateObject("ActLifeVBA.VBA.AutomationAktuar")
obj.AutomationMyType()
Result:
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Program Files\Python37\lib\site-packages\comtypes\safearray.py", line 223, in __ctypes_from_outparam__ return self[0] File "C:\Program Files\Python37\lib\site-packages\comtypes\safearray.py", line 214, in __getitem__ return self.unpack() File "C:\Program Files\Python37\lib\site-packages\comtypes\safearray.py", line 260, in unpack for d in range(1, dim+1)] File "C:\Program Files\Python37\lib\site-packages\comtypes\safearray.py", line 260, in <listcomp> for d in range(1, dim+1)] File "C:\Program Files\Python37\lib\site-packages\comtypes\_safearray.py", line 97, in SafeArrayGetLBound _SafeArrayGetLBound(pa, dim, result) OSError: exception: access violation reading 0x0000020C5073FFFC
Any ideas?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  method call help sollarriiii 6 1,078 Feb-21-2023, 03:19 AM
Last Post: noisefloor
  how to get around recursive method call Skaperen 10 4,191 Jul-01-2020, 10:09 PM
Last Post: Skaperen
  Polymorphism not working with a call to a abstract method colt 3 2,277 Nov-04-2019, 11:04 PM
Last Post: colt
  How to Call a method of class having no argument dataplumber 7 6,319 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  Call method from another method within a class anteboy65 3 7,351 Sep-11-2019, 08:40 PM
Last Post: Larz60+
  What is the use of call method and when to use it? everyday1 1 3,269 Jul-14-2019, 01:02 PM
Last Post: ichabod801
  I'm trying to figure out whether this is a method or function call 357mag 2 2,380 Jul-04-2019, 01:43 AM
Last Post: ichabod801
  How to call a method in a module using code KingPieter 4 2,965 Jan-15-2019, 09:13 PM
Last Post: KingPieter
  call method in class using threads? masterofamn 0 2,672 Jan-24-2017, 09:09 PM
Last Post: masterofamn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020