我现在有一个ActiveX控件,我要从一个控件中导出一个特别大的数组该怎么做?(不用文件方式,是直接用内存导出!)
                                     
                                                    请各位大侠指教。 谢谢!

解决方案 »

  1.   

    使用VARIANT,明天给你贴点代码你就知道了!
      

  2.   

    use memory stream
    see COleStreamFile
      

  3.   

    VARIANT myVar;
    myVar.vt = VT_CY;
    // put 15.15 into the currency variant.
    CURRENCY myValue;
    myValue.Hi = 0;
    myValue.Lo = (LONG)(15*10000 + 1537); // set the value to $15.15;
    myVar.cyVal = myValue;
    //or
    myValue.int64 = (151234);
    myVar.cyVal = myValue;



    //Now get the value from a float and put it into the currency.
    float myMoney = (float)5.37;
    myVar.vt = VT_R4;
    myVar.fltVal = myMoney;
    //no loss of precission.
    VariantChangeType(&myVar, &myVar, 0, VT_CY);
    //Now get the value from a String
    USES_CONVERSION;
    myVar.bstrVal = SysAllocString(L"23.4345");
    myVar.vt = VT_BSTR;
    VariantChangeType(&myVar, &myVar, 0, VT_CY); //Finally output a currency to a string.
    myVar.cyVal.int64 += myVar.cyVal.int64; // + myVar.cyVal;
    VariantChangeType(&myVar, &myVar, 0, VT_BSTR);


    }void CVarUseDlg::OnStrings() 
    {
    //Create a BSTR and assign it to a Variant
    BSTR x = SysAllocString(L"Hello");
    VARIANT myVariant;
    myVariant.vt = VT_BSTR;
    myVariant.bstrVal = x;
    SysFreeString(x); //Create a CString and change it to a variant;
    CString myCString(_T("My String"));
    CString mySecondString;


    //This is required to use the T2COLE macro.
    USES_CONVERSION;



    BSTR y = SysAllocString(T2COLE(myCString));
    myVariant.bstrVal = y;
    mySecondString = y;
    SysFreeString(y); _bstr_t str2="hjljljl";
    char *str1 = (char*)str2;//char*是_bstr_t类的一个重载
    CString str3=str1; //Create two BSTRs and add them.
    BSTR a = SysAllocString(L"One two ");
    BSTR b = SysAllocString(L"three four.");
    _bstr_t my_bstr_t(a, TRUE);
    my_bstr_t += b;
    myVariant.bstrVal = my_bstr_t;
    // or
    myVariant.bstrVal = _bstr_t(a, FALSE) + b; //Change a bstr to a CString.
    CString ANewString(b);
    //or if CString already exists.
    myCString = b;
    //Use of CComBSTR
    CComBSTR myCComBSTR(L"Hello");
    myCComBSTR.Append(L", how are you?");
    VARIANT varFromCCom;
    varFromCCom.vt = VT_BSTR;
    varFromCCom.bstrVal = myCComBSTR;

    }void CVarUseDlg::OnBasic() 
    {
    //create a variant of the character 'c'
    VARIANT varC;
    varC.vt=VT_UI1;
    varC.cVal = 'c'; //create a variant of the short 12
    VARIANT varS;
    varS.vt = VT_I2;
    varS.iVal = 12; //create a variant of the long 1234567;
    VARIANT varL;
    varL.vt = VT_I4;
    varL.lVal = 1234567;
    }void CVarUseDlg::OnSafeArray() 
    { //Create a standard array;
    int* pMyOriginalArray = new int[100];
    for(int 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_UI1, 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);


    VARIANT myVariant; 
    myVariant.parray = pMySafeArray;
    myVariant.vt = VT_ARRAY|VT_UI1; // state it's an array and what type it holds.

    //To put the SafeArray in a Variant

    //pass the Variant to a function call.
    FunctionCallWithVariant(myVariant);
      

  4.   

    请问这个VARIANT对数组的大小有限制吗?