简体   繁体   English

如何在(windows)tagVARIANT中存储字符串?

[英]How do you stock a string in a (windows) tagVARIANT?

How do you stock a string in a tagVARIANT without loosing (allocating) memory? 如何在不丢失(分配)内存的情况下将字符串存储在tagVARIANT中?

I'm using Microsoft SDK. 我正在使用Microsoft SDK。

Use _variant_t which has the according assignment operators. 使用具有相应赋值运算符的_variant_t。 If you have a VARIANT you can attach and detach it to the helper class. 如果您有一个VARIANT,则可以将其附加和分离到助手类。

something like this: 像这样的东西:

_bstr_t bstrVal(yourstring);
VARIANT varString;
varString.vt = VT_BSTR;
varString.bstrVal = bstrVal;

I have not compiled it so there may be compilation errors, but you get the idea. 我尚未编译它,因此可能存在编译错误,但是您明白了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM