从_variant_t转换为long(或char *) [英] Conversion from _variant_t to long (or char*)

查看:506
本文介绍了从_variant_t转换为long(或char *)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经在VC ++ 6.0中编写了一个代码,该代码针对ADODB连接&触发了对数据库的查询fetech将_variant_t var对象中的int数据.

Hello all,

I have written a code in VC++ 6.0,which fires a query to database against ADODB connection & feteches a int data in _variant_t var object.

_variant_t var;
var = recordset->Fields->GetItem(L"id")->GetValue();


现在,我要将这个"id"值存储在一个长数组中.为此,我需要将var中的值转换为long.
我尝试将var.lVal存储在数组中,但Dint起作用了.我可以看到的另一种选择是将 var转换为 char*&然后使用atol()转换为long.

如何实现两种转换(即转换为long或转换为char *)?


Now, I want to store this "id" value in a long array.For this I need to convert the value in var to long.
I tried storing var.lVal in the array but dint worked. Another option I can see is to convert var to char* & then use atol() to convert to long.

How to achieve either of the conversion (i.e. to long or to char*)?

Thanks.

推荐答案

要么查看类型(vt字段),然后读取基础VARIANT结构中的相关字段,要么使用
Either look at the type (the vt field), and then read the relevant field in the underlying VARIANT structure, or use one of the accessor functions[^].

Since the accessors may call VariantChangeType, you may not get the results you expect. Looking at the vt field is the more robust way to go.


这篇关于从_variant_t转换为long(或char *)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆