posts - 14, comments - 4, trackbacks - 0, articles - 0

SAFEARRAY使用方法示例

Posted on 2006-07-05 20:09 will 阅读(1168) 评论(0)  编辑 收藏 引用 所属分类: 技术探索

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 ;


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理