如何在Windows JScript中创建SAFEARRAY? [英] How to create a SAFEARRAY in Windows JScript?

查看:64
本文介绍了如何在Windows JScript中创建SAFEARRAY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows JScript中创建字节类型的SAFEARRAY.
您能给我一些示例代码或向我指出正确的方向吗?

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?

推荐答案

很麻烦,但 stripting.dictionary :: items 作为安全数组返回,因此在某些情况下(ADSI查询),以下工作有效,但是YMMV在尝试使用二进制数据方面表现出了很大的优势.

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])

这篇关于如何在Windows JScript中创建SAFEARRAY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆