开发者

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

开发者 https://www.devze.com 2023-03-18 00:23 出处:网络
I calling a third-party COM function in my VBScript. The method signature is as follows: HRESULTParseXML ([in] BSTR *textIn,[in] VARIANT_BOOL *aVa开发者_高级运维lidateIn,[out, retval] MSXML2.IXMLDOMD

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

HRESULT  ParseXML ([in] BSTR *textIn,[in] VARIANT_BOOL *aVa开发者_高级运维lidateIn,[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?


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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号