comtypes: how to provinde a list of string to a COM method - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: comtypes: how to provinde a list of string to a COM method (/thread-42372.html) |
comtypes: how to provinde a list of string to a COM method - zalanthas - Jun-26-2024 Working on Microsoft Windows [Version 10.0.19045.4412], Python 3.8.10 (I need to compile my script for Windows 7 as well...), comtypes 1.4.4 I am interacting with a Windows application through comtypes import comtypes.client import numpy as np from comtypes.automation import VARIANT comtypes.client.GetModule('path\to\application.exe') from comtypes.gen import Application as App comtypes.npsupport.enable() MyApp = comtypes.client.CreateObject('CLSID', interface=App.IDualApplication)and everything is working smooth: I found methods that asks for Variant (two-element array of double with array lower bound = 0 and array upper bound = 1) as an argument, defined as follows (inside its owner's class _methods_ list, of course) COMMETHOD( [dispid(id), helpstring('Perform this action')], HRESULT, 'ThisMethod', (['in'], VARIANT, 'dValues'), )I managed to deal with them with MyApp.ThisMethod(VARIANT(np.array([x, y], dtype='float')))Sweet! Now, I have a method that asks for String array as an argument, defined as follows (inside its owner's class _methods_ list, of course) COMMETHOD( [dispid(id), helpstring('Perform that action.')], HRESULT, 'ThatMethod', (['in', 'optional'], VARIANT, 'strArrayItems'), )Here's how I tried to deal with it, with the results I got: MyApp.ThatMethod(['x', 'y'])
MyApp.ThatMethod(VARIANT(np.array(['x', 'y'], dtype='str')))
variant = VARIANT(VT_ARRAY | VT_BSTR) variant.value = ['x', 'y'] MyApp.ThatMethod(variant)
variant = VARIANT(VT_ARRAY | VT_BSTR) variant.value = np.array(['x', 'y'], dtype='str') MyApp.ThatMethod(variant) How can I provide this COM method with a String array?
|