谁拥有返回的 BSTR? [英] Who owns returned BSTR?

查看:12
本文介绍了谁拥有返回的 BSTR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设来自 COM 接口的方法返回 BSTR 值.我认为我必须释放它是对的吗?

Suppose a method from a COM interface returns BSTR value. Am I right in my opinion that I must free it?

http://msdn.microsoft.com/en-us/library/aa365382(VS.85).aspx 不这样做.

谁错了?

推荐答案

MSDN 示例错误.调用者释放和输入/输出 bstrs.如果它是输入/输出,则必须传入 null 或有效的 bstr.如果只是out,就不用初始化了.

The MSDN sample is wrong. The caller frees out and in/out bstrs. If it's in/out you have to pass in null or a valid bstr. If it's out only, it doesn't have to be initialized.

从msdn的com分配规则看不太清楚,但是客户端存根在 out 值上分配内存,因此从调用者的角度来看,服务器确实如此.除了调用者还有谁可以释放它?

It's not super clear from msdn's com allocation rules, but the client stub allocates the memory on out values so from the caller's point of view the server did. Who else can free it but the caller?

这篇关于谁拥有返回的 BSTR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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