CString :: AllocSysString()需要是免费的吗? [英] CString::AllocSysString() needs to be free'd?

查看:71
本文介绍了CString :: AllocSysString()需要是免费的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


我正在使用VC ++ 7.0(.net 2002)和MFC。


我有一个功能(foo) )使用CString变量(strCommand)作为

参数。 foo正在通过ADO访问数据库。代码之一是:


pCommand-> put_CommandText(strCommand.AllocSysString());

我是否需要释放分配给字符串的内存或它会这样吗

自动吗?


// Anders


转到:microsoft.public.dotnet。 languages.vc,microsoft.pub lic.vc.language,microsoft.public.vc.mfc

回复将转至:microsoft.public.dotnet.languages.vc

解决方案

>我是否需要释放分配给字符串的内存,还是会自动执行




Anders,


文档说明如下:


"通常,如果此字符串传递给COM函数(作为[in]

参数)这要求调用者释放字符串。这可以通过使用SysFreeString来完成,如Platform SDK中所述。请参阅

字符串:为BSTR分配和释放内存以获取更多

有关确定调用者何时释放字符串的信息。

"


Dave


这实际上取决于您使用它的对象。在大多数情况下,

函数的调用者负责释放它。否则,

对象无法知道你是否已经完成了BSTR对象




所以,你可以使用:: SysFreeString()。


我总是喜欢使用CComBSTR代替这种方法。


干杯

Jagadeesh


" Anders Eriksson" <一个************* @ morateknikutveckling.se>在消息中写道

news:kd ************** @ morateknikutveckling.se ...

你好!
<我正在使用VC ++ 7.0(.net 2002)和MFC。

我有一个函数(foo)使用CString变量(strCommand)作为
参数。 foo正在通过ADO访问数据库。代码之一是:

pCommand-> put_CommandText(strCommand.AllocSysString());

我是否需要释放分配给字符串的内存或者它是否会这样做
自动?

// Anders

转到:
microsoft.public.dotnet.languages.vc,microsoft.pub lic.vc.language ,microsoft。

public.vc.mfc回复将转到:microsoft.public.dotnet.languages.vc



你必须释放它。

-

RodrigoCorralGonzález[MVP]


microsoft.public.es.vc常见问题解答
http://vcfaq.europe.webmatrixhosting.net

Hello!

I''m using VC++ 7.0 (.net 2002) and MFC.

I have a function (foo) that uses a CString variable (strCommand) as a
parameter. foo is accessing a database via ADO. Among the code is this:

pCommand->put_CommandText(strCommand.AllocSysString());
Do I need to free the memory allocated to string or will it do so
automatically?

// Anders

Crossposted to: microsoft.public.dotnet.languages.vc,microsoft.pub lic.vc.language,microsoft.public.vc.mfc
Replies will go to: microsoft.public.dotnet.languages.vc

解决方案

>Do I need to free the memory allocated to string or will it do so

automatically?



Anders,

The documentation says so:

"Commonly, if this string is passed to a COM function (as an [in]
parameter) this requires the caller to free the string. This can be
done by using SysFreeString, as described in the Platform SDK. See
Strings: Allocating and Releasing Memory for a BSTR for more
information on determining when the string is freed by the caller.
"

Dave


This actually depends upon the object you are using it with. In most cases,
the caller of the function is responsible for freeing it. Otherwise, the
object has no way of knowing whether you are finished with the BSTR object
or not.

So, you can use ::SysFreeString().

I always prefer using CComBSTR instead of this approach.

Cheers
Jagadeesh

"Anders Eriksson" <an*************@morateknikutveckling.se> wrote in message
news:kd**************@morateknikutveckling.se...

Hello!

I''m using VC++ 7.0 (.net 2002) and MFC.

I have a function (foo) that uses a CString variable (strCommand) as a
parameter. foo is accessing a database via ADO. Among the code is this:

pCommand->put_CommandText(strCommand.AllocSysString());
Do I need to free the memory allocated to string or will it do so
automatically?

// Anders

Crossposted to: microsoft.public.dotnet.languages.vc,microsoft.pub lic.vc.language,microsoft.
public.vc.mfc Replies will go to: microsoft.public.dotnet.languages.vc



You must free it.
--
Rodrigo Corral González [MVP]

microsoft.public.es.vc FAQ
http://vcfaq.europe.webmatrixhosting.net


这篇关于CString :: AllocSysString()需要是免费的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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