1

I have a COM function written in C++ using some VARIANT pointer as argument to return a value. I want to call that function with Python but I run out of solutions;

I tried to use VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_BYREF, value) from pywin32 and pythonnet python libraries with no success.

Here is the syntax of the COM function:

object.ExtendedGetSourceName(int iSource, VARIANT* ovSourceName) as Boolean

with:

object: a COM object
iSource: index of the source (starting from 0)
ovSourceName: name of the source

ovSourceName gets the returned value.

import win32com.client
import pythoncom

xmpmapPath = r"C:\LM.Irradiance.1.xmp"
XMPViewer = win32com.client.Dispatch("XMPViewer.Application") # START INSTANCE
XMPViewer.OpenFile(xmpmapPath)# Opens XMP file
iNbSource = XMPViewer.ExtendedGetNbSource #Returns the number of sources
for sourceindex in range(0, iNbSource):
    sSourceName = win32com.client.VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_BYREF, 1)

    RetVal = XMPViewer.ExtendedGetSourceName(sourceindex,  sSourceName) #Returns TRUE if the call has succeeded, FALSE otherwise.
    print(str(RetVal))
    print(str(sSourceName))

Visual Studio Codes returns

True
win32com.client.VARIANT(16396, 1)

Would you know how to make a COM variant pointer, then get its returned in Python?

3

0

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.