开发者

How to use IMalloc::Free?

开发者 https://www.devze.com 2023-01-03 22:10 出处:网络
I\'m using ICommandText::Ge开发者_StackOverflow中文版tCommandText method. According to the MSDN documentation (http://msdn.microsoft.com/en-us/library/ms709825(v=VS.85).aspx) I need to use IMalloc::Fr

I'm using ICommandText::Ge开发者_StackOverflow中文版tCommandText method. According to the MSDN documentation (http://msdn.microsoft.com/en-us/library/ms709825(v=VS.85).aspx) I need to use IMalloc::Free to release the memory allocated for LPOLESTR *ppwszCommand output parameter.

How do I use this interface to do that?


Just pass it to CoTaskMemFree, it's wrapping the same default OLE allocator CoGetMalloc is exposing.

CoTaskMemAlloc/Free are convenient shortcuts to IMalloc interface of the default OLE allocator so you can skip the cumbersome interface altogether.


You'll need to retrieve an IMalloc* pointer first - use CoGetMalloc() for that. Once you've got an IMalloc* pointer call IMalloc::Free(), passing the address of the block you want to free. Once you've finished with the IMalloc* pointer call IMalloc::Release() on the pointer or save it somewhere to reuse and free when you no longer need it.

0

精彩评论

暂无评论...
验证码 换一张
取 消