VBScript & ldquo; Type Mismatch & rdquo; Problem with & ldquo; [In, out] BSTR * & rdquo; parameter

advertisements

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


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.