How to create a SAFEARRAY in Windows JScript?
I want to create a SAFEARRAY of type byte in Windows JScript.
Can you give me some example code or p开发者_JS百科oint me in the right direction?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])
JScript doesn't allow you to create safe arrays, you would probably need to write an ActiveXObject to handle this for you.
精彩评论