Having hard time passing VARIANT* input Parameter to a COM object.

shkshk90+ironpython@...
 

Hello,

 

This was probably answered several times, and I checked almost every documentation available online, and stackOverflow, and nothing seems to work.

At my company, we are using an internal tool, that has a COM object, and we want to call it from IronPython.
The function that I am trying to use, merges several files, and has the following signature (in VBA):
--   object.Merge(VARIANT* pInputListFiles, BSTR strOutputFileName) As Integer
The provided example is as follows (in VBA):
====================================================================

Dim Error As Integer
Dim App As Object
Set App = CreateObject("Viewer.Application")

Dim FileTab
ReDim FileTab(2)
FileTab(0) = "C:\file1.ext"
FileTab(1) = "C:\file2.ext"

Error = App.Merge(FileTab, "C:\file1+2.ext")
MsgBox ("Files Merged")

====================================================================

I am trying to do the the same in IronPython, I created the object successfully, and I can call any function that takes non-Variant input.
However, when a Variant* input is required, that refers to an array, I always get the famous ValueError.

The following happens here's all my trials,

====================================================================

>>> import clr
>>> from System import Array
>>> from System.Runtime.InteropServices import Marshal
>>> from System import String, Single
>>> from System.Type import GetTypeFromProgID
>>> from System.Activator import CreateInstance
>>> apptype= GetTypeFromProgID("Viewer.Application")
>>> app = CreateInstance(apptype)
>>> app.OpenFile(r"C:\file0.txt") # TAKES A BSTR, WORKS FINE
1

>>> app.Merge([r"C:\file1.txt", r"C:\file2.txt"], r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.

>>> app.Merge(Array[string](
[r"C:\file1.txt", r"C:\file2.txt"]), r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.

>>> ref = clr.Reference[Array[String]](Array[String]([r"C:\file1.txt", r"C:\file2.txt"]))
>>> app.Merge(ref, r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.

>>> s1 = clr.Reference[String]()

>>> s1.Value = r"C:\file1.txt"
>>> app.Merge(s1, r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.

>>> s1 = clr.Reference[Array[String]]()
>>> s1.Value = Array[str]([r"C:\file1.txt", r"C:\file2.txt"])
>>> app.Merge(s1, r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.


>>> s2 = clr.Reference[Array[object]]()
>>> s2.Value = Array[
object]([r"C:\file1.txt", r"C:\file2.txt"])
>>> app.Merge(s2, r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.


>>> s2 = clr.Reference[object]()
>>> s2.Value = Array[
object]([r"C:\file1.txt", r"C:\file2.txt"])
>>> app.Merge(s2, r"C:\file3.txt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert argument 1 for call to Merge.

>>> ref = clr.Reference[object]()
>>> app.Merge(ref, r"C:\file3.txt") # WORKS FINE, HOWEVER, THIS IS AN IN PARAMETER, NOT OUT
0

====================================================================


I am over my head with this error, does anyone have any idea to guide me?

Documentation and/or links are highly welcomed.

 

I truly appreciate the help.

Thank you so much for your time.

 

Best regards,

Join users@ironpython.groups.io to automatically receive all group messages.