Lance
Lance

Reputation: 491

Passing a string in VBScript to a COM Function which expects a BSTR*

I calling a third-party COM function in my VBScript. The method signature is as follows:

HRESULT  ParseXML ([in] BSTR *textIn,[in] VARIANT_BOOL *aValidateIn,[out, retval] MSXML2.IXMLDOMDocument2 **aXMLDocOut)

In my VBScript the following call gives back a type mismatch:

Dim someText
someText = "Hello"
Dim response
response = ParseXml(someText, False)

But passing in the string literal works fine:

Dim response
response = ParseXml("Hello", False)

Any ideas what I need to do on the VBScript side?

Upvotes: 1

Views: 2631

Answers (2)

GSerg
GSerg

Reputation: 78185

BSTR is already a pointer.
BSTR* is therefore a pointer to pointer.

That is, you are passing a string by reference (ByRef textIn As String).

When you pass a variable by reference, the types must match. someText is VARIANT.

If you were to pass just BSTR (ByVal textIn As String), VB would handle the conversion for you.

Any ideas what I need to do on the VBScript side?

If you are sure it's the script you want to fix, not the library, then trick VB into using a temp variable which will be passed by ref:

response = ParseXml((someText), False)

Upvotes: 1

user128300
user128300

Reputation:

Did you really write ParseXml(somText, False) in your script? Then it is a typo; it should be someText.

Upvotes: 0

Related Questions