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

问题描述

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

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

不会这样做。

The code example at http://msdn.microsoft.com/en-us/library/aa365382(VS.85).aspx does not do that.

谁错了?

推荐答案

MSDN示例错了。调用者释放和输入/输出bstrs。如果它在/ out,你必须传入null或有效的Bstr。

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的,但是客户端存根分配内存的值,所以从调用者的角度来看,服务器。还有谁可以释放它,但呼叫者?

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 04:46