ActiveX Type mismatch...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ActiveX Type mismatch...

Christopher J. Demers
I have an ActiveX library I am trying to use, but I have a method giving me
an "HRESULT Error: Type mismatch. (FACILITY_DISPATCH)" error.

The method Dolphin generated is:
===========
loadJob: bstrJobPath
 "Answer the <VARIANT_BOOL> result of invoking the COM Object's LoadJob()
method."

 ^(self invokeId: 1 with: bstrJobPath)
===========

The documentation shows the definition as:

boolean LoadJob(BSTR* bstrJobPath);

I have passed bstrJobPath  as a string, and even as a BSTR.  Does anyone
have
any wisdom they can share with me regarding this?  This works from VBA in
Excel.  Any ideas?

Chris


Reply | Threaded
Open this post in threaded view
|

Re: ActiveX Type mismatch...

Blair McGlashan
"Christopher J. Demers" <[hidden email]> wrote in
message news:a4c099$1cijso$[hidden email]...
> I have an ActiveX library I am trying to use, but I have a method giving
me

> an "HRESULT Error: Type mismatch. (FACILITY_DISPATCH)" error.
>
> The method Dolphin generated is:
> ===========
> loadJob: bstrJobPath
>  "Answer the <VARIANT_BOOL> result of invoking the COM Object's LoadJob()
> method."
>
>  ^(self invokeId: 1 with: bstrJobPath)
> ===========
>
> The documentation shows the definition as:
>
> boolean LoadJob(BSTR* bstrJobPath);
>
> I have passed bstrJobPath  as a string, and even as a BSTR.  Does anyone
> have
> any wisdom they can share with me regarding this?  This works from VBA in
> Excel.  Any ideas?

For some reason the parameter is passed by ref. (as a BSTR*), not a BSTR.
This will cause a problem if you invoke it passing a string if calling via
IDispatch, since the default conversion of a String/BSTR to a VARIANT will
construct a VT_BSTR, not a VT_BSTR|VT_BYREF. Try instead:

bstrJobPath := aString asBSTR.
var := VARIANT new.
var ulVal: bstrJobPath basicYourAddress.
obj loadJob: var.

Pass-by-ref should really only be used for [out] and [in-out] parameters
(i.e. where the method may want to pass back data by overwriting the
pointer), so if this parameter is really [in] only, which looks likely, I
suggest modifying the generated #loadJob: method to incorporate the above
set-up of the variant to be passed to #invokeId:with:.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: ActiveX Type mismatch...

Christopher J. Demers
Blair McGlashan <[hidden email]> wrote in message
news:a4gd4d$2n68$[hidden email]...
> For some reason the parameter is passed by ref. (as a BSTR*), not a BSTR.
> This will cause a problem if you invoke it passing a string if calling via
> IDispatch, since the default conversion of a String/BSTR to a VARIANT will
> construct a VT_BSTR, not a VT_BSTR|VT_BYREF. Try instead:
>
> bstrJobPath := aString asBSTR.
> var := VARIANT new.
> var ulVal: bstrJobPath basicYourAddress.
> obj loadJob: var.

Thank you Blair!  I probably should have remembered this from my C days.
Smalltalk has spoiled me.  The approach you described works like a charm.
However I had to add one line:
    var vt: VT_BSTR|VT_BYREF.

Thanks,
Chris