How to return XLOPER (Excel Variable) to VBA directly from a c++ dll?

爷,独闯天下 提交于 2019-12-04 22:07:16

finally I read attentively the book "Excel Add-in Development in C / C++, 2nd Edition by Steve Dalton". It answers the question and provides source code for it. If you want to perform this operation you need to create a xloper wrapper, the xloper_to_v function which is par of xloper.cpp of the aforementioned book do this job. Due to copyrights, I can't publish here the whole code but just some lines of codes; i think it can give some useful insight:

bool xloper_to_vt(const xloper *p_op, VARIANT &var, bool convert_array)
{
VariantInit(&var); // type is set to VT_EMPTY

switch(p_op->xltype)
{
case xltypeNum:
    var.vt = VT_R8;
    var.dblVal = p_op->val.num;
    break;

case xltypeInt:
    var.vt = VT_I2;
    var.iVal = p_op->val.w;
    break;

case xltypeBool:
   // see in the book

case xltypeStr:
    // see in the book

case xltypeErr:
    // see in the book

case xltypeMulti:
    if(convert_array)
    {
        VARIANT temp_vt;
        SAFEARRAYBOUND bound[2];
        long elt_index[2];

        // see in the book

        xloper *p_op_temp = p_op->val.array.lparray;

        for(WORD r = 0; r < p_op->val.array.rows; r++)
        {
            for(WORD c = 0; c < p_op->val.array.columns;)
            {
            // see in the book
            }
        }
        break;
    }
    // else, fall through to default option

default: // type not converted
    return false;
}
return true;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!