I'm using ICommandText::GetCommandText 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?
You'll need to retrieve an
IMalloc*
pointer first - useCoGetMalloc()
for that. Once you've got anIMalloc*
pointer callIMalloc::Free()
, passing the address of the block you want to free. Once you've finished with theIMalloc*
pointer callIMalloc::Release()
on the pointer or save it somewhere to reuse and free when you no longer need it.Just pass it to
CoTaskMemFree
, it's wrapping the same default OLE allocatorCoGetMalloc
is exposing.CoTaskMemAlloc/Free
are convenient shortcuts toIMalloc
interface of the default OLE allocator so you can skip the cumbersome interface altogether.