associative array from javascript to activex object
I need to pass an associative arra开发者_Go百科y from Javascript to a C++ activex control in IE6+. It seems a shame to write my own type for something so standard. It doesn't have to work with native JS objects, I can use a custom associative array type if I need.
I've been googling for a couple days and there isn't a lot of information on this subject. COM and ATL have to have this already, don't they?
This post by Eric Lippert may shed some light on how it could be done from C++. Take a look at his comments about a Javascript array being a Dispatch object. As such you could get the DISPIDs and call Invoke on each one. Another option is to convert the Javascript array to a SafeArray
using VBArray (and a little VBScript), or you could just use the Scripting.Dictionary COM object, which is the equivalent of an associative array. A few resources are below.
http://blogs.msdn.com/b/david.wang/archive/2006/07/04/howto-convert-between-jscript-array-and-vb-safe-array.aspx
http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/DictionaryKeys.htm
精彩评论