惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
The Register - Security
The Register - Security
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园_首页
U
Unit 42
T
Tailwind CSS Blog
G
GRAHAM CLULEY
F
Full Disclosure
V
Vulnerabilities – Threatpost
T
Tenable Blog
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
K
Kaspersky official blog
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
有赞技术团队
有赞技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LINUX DO - 最新话题
Recorded Future
Recorded Future
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Help Net Security
Help Net Security
The GitHub Blog
The GitHub Blog
Cisco Talos Blog
Cisco Talos Blog
SecWiki News
SecWiki News
P
Proofpoint News Feed
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
罗磊的独立博客
S
Security Affairs
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
美团技术团队
Simon Willison's Weblog
Simon Willison's Weblog
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
V
Visual Studio Blog

博客园 - 痛并快乐着

linux redhat 中的网络配置 Javascript 自适应iframe页面大小(有效) - 痛并快乐着 - 博客园 在网页上点击链接激活MSN对话窗口。 - 痛并快乐着 - 博客园 asp枚举指定目录下的文件。 - 痛并快乐着 - 博客园 防止网页上的图片被保存 - 痛并快乐着 - 博客园 Asp/asp.net中下拉列表的N级联动 - 痛并快乐着 - 博客园 在MFC类中各种类的指针的获取和应用 Socket中如何设置连接超时 - 痛并快乐着 - 博客园 VC++实现对远程计算机屏幕的监视 SOCKET编程总结 - 痛并快乐着 - 博客园 VC操纵IIS - 痛并快乐着 - 博客园 几个有用的vbs脚本 - 痛并快乐着 - 博客园 WSH脚本宿主Wscript脚本主对象 读取硬盘物理序列号 5.7 使用通用对话框 VC读写注册表 VC常用编程经验 - 痛并快乐着 - 博客园 按键精灵高级脚本 选择目录 - 痛并快乐着 - 博客园
_com_util::ConvertStringToBSTR 使用时的注意事项
痛并快乐着 · 2006-01-28 · via 博客园 - 痛并快乐着

在进行COM编程的时候常常用到VARIANT类型的变量, 其中的字符串分量为bstrVal即双字节的BSTR, 如果需要将其转换为字符串STRING我以前使用强制类型转换:
    (const char*)bsVal;
在看了潘爱民老师的<<COM编程原理>>偶尔发现如下函数(例子摘自MSDN)

   //compile options needed: /Gr or /Gz
   #include <comutil.h>
   int main()
   {
       char sz[]="hello";
       _bstr_t b;
       b = _com_util::ConvertStringToBSTR(sz);
       char * p = _com_util::ConvertBSTRToString(b);
       return 1;
   }

注意: 上述代码编译时候出现如下错误

error LNK2001: unresolved external symbol "char * __fastcall
   _com_util::ConvertBSTRToString(unsigned short *)"
   (?ConvertBSTRToString@_com_util@@YIPADPAG@Z)

   error LNK2001: unresolved external symbol "unsigned short * __fastcall
   _com_util::ConvertStringToBS
   TR(char const *)" (?ConvertStringToBSTR@_com_util@@YIPAGPBD@Z)

解决: 在Link页加入comsupp.lib就可以了, 不过我的程序编译的时候没有上述错误, 但是在同事的机器上出现了.

我的用法 -- _com_util::ConvertStringToBSTR();

    char*   pTemp;
    CString csTemp;

    pTemp = _com_util::ConvertBSTRToString(bsVal);
    csTemp = pTemp;
    delete pTemp;
    pTemp = NULL;

    // 这是我们公司的一位高手的最安全的用法
    // 对于ConvertStringToBSTR不需要