1

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!

1
  • If you can create an instance of Scripting.Dictionary from Javascript and add the values to it, the Items property will return a SAFEARRAY of the elements. Commented Feb 13, 2018 at 5:33

2 Answers 2

2

Arrays in JScript are no distinct types, they are just objects that have a property length and allow access to their contents via properties.
In your Invoke()/InvokeEx() method, the VARIANT argument you receive should contain an IDispatch, which represents the scriptable object. On that retrieve the property length and get the contents via the property names 0 to length-1.

As an implementation example, see e.g. FireBreaths IDispatchAPI::GetProperty() (IDispatchAPI wraps the scriptable browser object there). dispApi->GetProperty("length") would get the size of the array, while dispApi->GetProperty("0") to length-1 would get the actual content of the array.

Sign up to request clarification or add additional context in comments.

3 Comments

Yup, looks like IDispatch is the way to go seeing as how my Javascript code does indeed create a VARIANT of type IDispatch. Thanks for the heads up.
@Georg: Is there any sample which i can refer to get the bytes from VARIANT?
@Jeeva: FireBreaths VARIANT conversion is here. Putting that together with the GetPropery() implementation above should get you going.
1

I have been struggling with this in a project 5 years ago. We ended up exchanging strings between JavaScript and COM, because they have low overhead and can easily be exchanged. If the data is truly binary, you will have to encode it. We used base64, but you could also add 0x100 to all byte values, because strings are unicode (16bit character) on either side anyway.

1 Comment

Your solution can work as a proof-of-concept that the two end-nodes are correctly exchanging data, but it's not the optimal solution in terms of automation. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.