How to create a SAFEARRAY in Windows JScript?

后端 未结 2 886
感情败类
感情败类 2021-01-13 15:37

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?

相关标签:
2条回答
  • 2021-01-13 15:56

    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])
    
    0 讨论(0)
  • 2021-01-13 16:03

    JScript doesn't allow you to create safe arrays, you would probably need to write an ActiveXObject to handle this for you.

    0 讨论(0)
提交回复
热议问题