Search code examples
comvbscriptbstr

VBScript "Type Mismatch" issue with "[in, out] BSTR * " parameter


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

  • 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