In my Python program, I am trying to make a call to a custom COM object written in C++. The function I'm trying to call is constructed like this:
void foo(
BSTR *pbstrParameters,
BSTR *pbtrResult
);
It is my understanding that Python converts unicode strings to BSTR variants when passing to COM objects. Perfect! That's what my function is expecting. Theoretically, I should be able to make the call like this:
COMobject.foo("string1","string2")
But that results in a type mismatch error: pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1)
Next, I tried passing it actual BSTRs from the comtypes module:
COMobject.foo(comtypes.BSTR("string1"),comtypes.BSTR("string2"))
, but that also resulted in a Type mismatch.
Lastly, I tried passing pointers to BSTRs, as defined in the comtypes _ctype_to_vartype
dictionary.
COMobject.foo(POINTER(BSTR),POINTER(BSTR))
Which results in the error: TypeError: Objects of type '_ctypes.PyCPointerType' can not be converted to a COM VARIANT
If I can't convert POINTER(BSTR)
to a COM variant, then what is this line in the comtypes' _ctype_to_vartype
dict in automation.py for?:
POINTER(BSTR): VT_BYREF|VT_BSTR,