VBScript “Type Mismatch” issue with “[in, out] BSTR * ” parameter
Question
I'm working with third-party COM object that has some of its methods passing values back as BSTR pointer. Since VBscript supports only Variant type attempts to use in a way like Object.Method(sMyString) reasonably end with "Type mismatch" error.
I suspect this error is generated by the COM object itself rather then VBscript interpreter since the object gets string instead of pointer. I tried to workaround it defining array of strings but it's still the same error.
So I was wondering if someone had similar problem and what workarounds were utilized.
Just to emphasize. I DO NOT have control over COM object. It's in Vendor's application. I have to use it "as is".
Thank you, Albert Gareev
Solution 2
After consideration of wrapper workaround I found that using existing COM Automation object has some advantages versus developing your own API.
Since I already use Excel.Application object for other purposes I just created a couple of macros in VBA and execute them as needed.
More details in my blog posts:
http://automation-beyond.com/2009/09/21/gp-qtp-automation-sanscript/
http://automation-beyond.com/2009/09/23/gp-automation-vbscript-limitation/
Thank you, Albert Gareev
OTHER TIPS
The rules for the types that VBScript is allowed to use a bit restricted compared to other languages. In your case, you have [in, out] BSTR *
- this is not supported. The only type allowed for an [out]
parameter is VARIANT *
. VBScript would require the type to be [out, retval] in order to support the BSTR
type in that position. Of course you can only have one [retval]
per function so that is somewhat limiting.
In any case in your situation, you are kind of stuck since you cannot modify the server code. What I would do is write a COM wrapper in C++ that wraps the API into something that you can call. The COM wrapper can change the [out] BSTR *
to an [out] VARIANT *
or something else that is usable.