1

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?

makdad
  • 6,402
  • 3
  • 31
  • 56
Lance
  • 411
  • 2
  • 6
  • 18

2 Answers2

1

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)
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • Thanks, updating the script using the temp variable worked fine. It's a third-party lib so updating the library wasn't an option. Thanks again. – Lance Jul 08 '11 at 08:54
0

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

  • Sorry, that was a typo when writing the question, no typo existed in the actual script. – Lance Jul 08 '11 at 08:55