zoukankan      html  css  js  c++  java
  • SAFEARRAY使用方法示例

    SAFEARRAY使用方法示例

     

    SAFEARRAY不是很好用,一些函数不太直观,一不小心就着了它的道。上次学习编写Google桌面插件时就遇到了麻烦,本来应该是vsa.vt = VT_ARRAY | VT_BSTR,结果写成了vsa.vt = VT_ARRAY,让我查了好久才找到原因。这里整理一下,作为备忘。

     

    l         创建

                                long i = 0;

                                VARIANT va = {0};

                                va.vt = VT_BSTR;

                               

                                SAFEARRAYBOUND bounds[1] = {0};

                                bounds[0].cElements = 5;

                                SAFEARRAY* psa = SafeArrayCreate(VT_VARIANT, 1, bounds);

     

    l         存入元素

                                for(i = 0; i < 5; i++)

                                {

                                         va.bstrVal = SysAllocString(L"test");

                                         SafeArrayPutElement(psa, &i, &va);

                                }

     

    l         获取元素

                                for(i = 0; i < 5; i++)

                                {

                                         va.bstrVal = SysAllocString(L"test");

                                         SafeArrayGetElement(psa, &i, &va);

                                         SysFreeString(va.bstrVal);

                                }

     

    l         销毁

                                SafeArrayDestroy(psa);

     

    l         生成VARIANT变量

                                VARIANT vsa = {0};

                                vsa.vt = VT_ARRAY | VT_BSTR;

                                vsa.parray = psa;

     

  • 相关阅读:
    Excel导入
    Git 操作命令
    java线程池
    jquery 初始化数据 添加html 第一次玩0.0
    设计模式六大原则之二:里氏替换原则
    升级指令
    strtok和strtok_r(转载)
    docker进阶之路-基础篇 | 二:portainer安装与基本使用
    docker进阶之路-基础篇 | 一:环境搭建
    集群式Quartz定时任务框架实践
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6167887.html
Copyright © 2011-2022 走看看