从_variant_t转换为long(或char *) [英] Conversion from _variant_t to long (or 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结构中的相关字段,要么使用 ^ ].
由于访问器可能会调用VariantChangeType,因此您可能无法获得预期的结果.查看vt字段是更可靠的方法.
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屋!