<p>I need to call into a Win32 API to get a series of strings, and I would like to return an array of those strings to JavaScript. This is for script that runs on local machine for administration scripts, not for the web browser.</p>

<p>My IDL file for the COM object has the interface that I am calling into as:</p>

<pre>
HRESULT GetArrayOfStrings([out, retval] SAFEARRAY(BSTR) * rgBstrStringArray);
</pre>

<p>The function returns correctly, but the strings are getting 'lost' when they are being assigned to a variable in JavaScript.</p>

<p>The question is:
What is the proper way to get the array of strings returned to a JavaScript variable?
­­­­­­­­­­­­­­­­­­­­­­­­</p>

[{'answer_id': 45211, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 4, 'selected': True, 'text': '<p>If i recall correctly, you\'ll need to wrap the <code>SAFEARRAY</code> in a <code>VARIANT</code> in order for it to get through, and then use a <a href="http://msdn.microsoft.com/en-us/library/y39d47w8(VS.85).aspx" rel="noreferrer">VBArray object</a> to unpack it on the JS side of things:</p>\n\n<pre><code>HRESULT GetArrayOfStrings(/*[out, retval]*/ VARIANT* pvarBstrStringArray)\n{\n   // ...\n\n   _variant_t ret;\n   ret.vt = VT_ARRAY|VT_VARIANT;\n   ret.parray = rgBstrStringArray;\n   *pvarBstrStringArray = ret.Detach();\n   return S_OK;\n}\n</code></pre>\n\n<p>then</p>\n\n<pre><code>var jsFriendlyStrings = new VBArray( axOb.GetArrayOfStrings() ).toArray();\n</code></pre>\n'}, {'answer_id': 67049, 'author': 'Euro Micelli', 'author_id': 2230, 'author_profile': 'https://Stackoverflow.com/users/2230', 'pm_score': 1, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/45169/how-do-i-return-an-array-of-strings-from-an-activex-object-to-jscript#45211">Shog9</a>\nis correct. COM scripting requires that all outputs be VARIANTS. </p>\n\n<p>In fact, it also requires that all the <strong>INPUTs</strong> 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.</p>\n'}]
['https://Stackoverflow.com/questions/45169', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1462171/']