c++ - Return multiple variables to JavaScript from COM -
i have com function in disp
interface shown below,
[id(1)] hresult multiplereturn([out]bstr* arg1, [out, retval] bstr* arg2);
implemented
stdmethodimp somecoolobject::multiplereturn(bstr* arg1, bstr* arg2) { *arg1 = sysallocstring(l"test1"); *arg2 = sysallocstring(l"test2"); return s_ok; }
in python can call
import comtypes.client cc obj = cc.createobject('somecoolobject') = obj.multiplereturn() print(a) # gives (u'test1', u'test2'), python, see don't bite :)
same in javascript
var obj = new activexobject("somecoolobject") // gives error, kind of obvious // 'wrong number of arguments or invalid property assignment' // var val = obj.multiplereturn(); var = "holaaa!"; var val = obj.multiplereturn(a); alert(val); // gives "test2" alert(a); // gives "holaaa!", may have given "test1"
this proves, javascript won't play ball. why? if not, how return multiple values com javascript. particular job, returned json though.
javascript/com binding doesn't support [out]
parameters - [out, retval]
(of which, of course, there can one). javascript doesn't have notion of pass-by-reference.
there several ways can closer goal.
return
safearray
of 2 strings. in javascript, consume viavbarray
object.implement simple com object 2
bstr
properties, create , return instance of object via[out, retval] idispatch**
.take
idispatch*
[in]
parameter, set new property on viaidispatchex::getdispid(fdexnameensure)
. javascript consume this:
.
var outparam = {}; var result = obj.multiplereturn(outparam); var secondresult = outparam.value;
(where value
name of property method creates on object).
Comments
Post a Comment