I want to create a SAFEARRAY of type byte in Windows JScript.
Can you give me some example code or point me in the right direction?
Asked
Active
Viewed 2,687 times
4

shane87
- 3,090
- 12
- 51
- 65
2 Answers
4
Hacky but stripting.dictionary::items
is returned as a safe array so in some circumstances (ADSI queries) the following works, however YMMV significantly in trying this with binary data.
function getSafeArray(jsArr) {
var dict = new ActiveXObject("Scripting.Dictionary");
for (var i = 0; i < jsArr.length; i++)
dict.add(i, jsArr[i]);
return dict.Items();
}
//to a safe array
var safearr = getSafeArray([11,22,33]);
//back to a js array
var jsArr = new VBArray(safearr).toArray();
log(jsArr[2])

Alex K.
- 171,639
- 30
- 264
- 288
1
JScript doesn't allow you to create safe arrays, you would probably need to write an ActiveXObject to handle this for you.

Andy E
- 338,112
- 86
- 474
- 445