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.

  1. return safearray of 2 strings. in javascript, consume via vbarray object.

  2. implement simple com object 2 bstr properties, create , return instance of object via [out, retval] idispatch**.

  3. take idispatch* [in] parameter, set new property on via idispatchex::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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -