I’m having a bit of a problem because neither Javascript nor ActiveX (written in C++) are behaving like good little children. All I’m asking them to do is for Javascript to send a byte array and for the ActiveX to receive the byte array correctly in order to do more computation.
This is how I declared my byte array in JS, and I verified it inside JS:
var arr = new Array(0x00, 0xA4, 0x04, 0x00, 0x10,0xA0, 0x00, 00, 00, 0x18, 0x30, 0x03, 0x01, 00, 00, 00, 00, 00, 00, 00, 00);
Javascript sends this array as an argument to an ActiveX method. Here is the tricky part; I want the ActiveX method to receive the byte array as a SAFEARRAY or VARIANT, but I can’t get it to work for the life of me.
I tried debugging and seeing the contents received inside the ActiveX as both SAFEARRAY or VARIANT, but to no avail. Here is the IDL segment:
[id(7), helpstring("blah blah blah")] HRESULT Blah( [in] VARIANT blah1, [out, retval]VARIANT* blah2);
Any help is greatly appreciated. Thanks in advance!
Arrays in JScript are no distinct types, they are just objects that have a property
lengthand allow access to their contents via properties.In your
Invoke()/InvokeEx()method, theVARIANTargument you receive should contain anIDispatch, which represents the scriptable object. On that retrieve the propertylengthand get the contents via the property names0tolength-1.As an implementation example, see e.g. FireBreaths
IDispatchAPI::GetProperty()(IDispatchAPIwraps the scriptable browser object there).dispApi->GetProperty("length")would get the size of the array, whiledispApi->GetProperty("0")tolength-1would get the actual content of the array.