VBScript error "Type of mismatch" with parameter "[in, out] BSTR *"

I work with a third-party COM object, in which some of its methods pass values ​​back as a BSTR pointer. Since VBscript only supports attempts of the Variant type to be used in such a way as Object.Method (sMyString), it is reasonable to end up with a "Mismatch Type" error.

I suspect that this error is generated by the COM object itself, and not by the VBscript interpreter, since the object receives a string instead of a pointer. I tried a workaround to define an array of strings, but it still remains the same error.

So I was wondering if anyone had a similar problem and what workarounds were used.

Just to emphasize. I have no control over the COM object. This is a vendor application. I have to use it "as is".

Thanks Albert Gareev

+2
source share
2 answers

After reviewing the wrapper workaround, I found that using an existing COM Automation object has some advantages over developing your own API.

Since I already use the Excel.Application object for other purposes, I just created a couple of macros in VBA and executed 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/

Thanks Albert Gareev

0
source

Rules for types that are allowed by VBScript to use a bit limited in comparison with other languages. In your case, you have [in, out] BSTR * - this is not supported. The only type allowed for the [out] parameter is VARIANT * . VBScript requires the type to be [out, retval] in order to maintain the BSTR type at this position. Of course, you can only have one [retval] per function, which is somewhat restrictive.

In any case, you are stuck in your situation, since you cannot change the server code. What I would like to do is write a C ++ COM wrapper that wraps the API in what you can call. The COM shell can change [out] BSTR * to [out] VARIANT * or something else that can be used.

+6
source

Source: https://habr.com/ru/post/1347881/


All Articles