How do I return an array of strings from an ActiveX object to JScript

﹥>﹥吖頭↗ 提交于 2019-12-05 10:43:09

If i recall correctly, you'll need to wrap the SAFEARRAY in a VARIANT in order for it to get through, and then use a VBArray object to unpack it on the JS side of things:

HRESULT GetArrayOfStrings(/*[out, retval]*/ VARIANT* pvarBstrStringArray)
{
   // ...

   _variant_t ret;
   ret.vt = VT_ARRAY|VT_VARIANT;
   ret.parray = rgBstrStringArray;
   *pvarBstrStringArray = ret.Detach();
   return S_OK;
}

then

var jsFriendlyStrings = new VBArray( axOb.GetArrayOfStrings() ).toArray();
Euro Micelli

Shog9 is correct. COM scripting requires that all outputs be VARIANTS.

In fact, it also requires that all the INPUTs be VARIANTS as well -- see the nasty details of IDispatch in your favorite help file. It's only thought the magic of the Dual Interface implementation by ATL and similar layers (which most likely is what you are using) that you don't have to worry about that. The input VARIANTs passed by the calling code are converted to match your method signature before your actual method is called.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!