如题,有两个问题:
 1.希望ActiveX 控件接口函数返回 char[],也就是字节数组,
  但开发环境不能定义这种返回值类型,
  2. 如果定义为指针类型,但是,调用这个ActiveX 的语言不支持指针,怎么办?

解决方案 »

  1.   

      javaScript vbscripb是否识别 SAFEARRAY...VARIANT类型类型呢?
      

  2.   


       ActiveX 有个简单接口,DoSomeThing(),返回100个字节的char [],
       然后,脚本调用DoSomeThing得到这100字节,
      要写成 VARIANT DoSomeThing()形式的接口么,脚本如何读取 VARIANT 类型?  谁能给一个简单例子么?
       
      

  3.   

    vbscript可以识别转换为VBArray,javascript也可以用这个...
      

  4.   

      
    VC2008的MSDN里面有个例子,ATLSafeArray ,是用ATL做的一个简单例子
    我仿照用MFC类库做了一个ActiveX控件,控件提供一个方法 VARIANT CFeb16Ctrl::DoSomeThing() 
      我试图将100个整数装在SAFEARRAY里面,然后用VARIANT 返回给调用者
       控件在VC程序中使用正常,在网页上也正常显示,但当用JSCRIPT脚本调用DoSomeThing()方法时有异常
      是我的控件不符合脚本调用要求,还是JSCRIPT脚本写的有问题啊
       MSDN里那个例子,运行的很好啊。
       下面是JScript函数和我的控件接口代码:  
      <SCRIPT LANGUAGE="JSCRIPT">
        function TestActiveFun()
        {
         var theResult = Feb16.DoSomething();
         for(var nCntr = theResult.lbound(1); nCntr <= theResult.ubound(1); nCntr++) //ie浏览器提示这行出错:“缺少对象”
       {
        var text = theResult.getItem(nCntr);
        document.writeln(text); 
             }
         }
       </SCRIPT>     //模仿MSDN ATLSafeArray 例子做的
        VARIANT CFeb16Ctrl::DoSomeThing() 
         { int* pMyOriginalArray = new int[100];
    int count;
    for(count = 0; count < 100; count++) pMyOriginalArray[count] = count;
    //Now get ready to put it into a safe array
    HRESULT hr;
    //create an array bound
    SAFEARRAYBOUND rgsabound[1];
    rgsabound[0].lLbound = 0; //The first (and only) collumn of our array starts at 0.
    rgsabound[0].cElements = 100; //and has 100 elements.

    //create the array
    SAFEARRAY FAR* pMySafeArray;
    pMySafeArray = SafeArrayCreate(VT_I4, 1, rgsabound); //create the array of 4byte integers, one dimension
    //with the bounds stored in rgsabound.

    //now access the safe array's data.
    int* pData;
    hr = SafeArrayAccessData(  pMySafeArray, (void**)&pData); //Get a pointer to the data.


    //copy the 400 bytes of data from our old array to the new one.
    memcpy(pData, pMyOriginalArray, 400);

    //here we verify to you that the data is correct.
    for(count = 0; count < 100; count++) ASSERT(pData[count] == pMyOriginalArray[count]);
    SafeArrayUnaccessData(pMySafeArray);

    //To put the SafeArray in a Variant
    VARIANT myVariant; 
    myVariant.parray = pMySafeArray;
    myVariant.vt = VT_ARRAY|VT_I4; // state it's an array and what type it holds.
    delete[] pMyOriginalArray;
    return myVariant;
    }