关于什么时候使用CoTaskMemAlloc/CoTaskMemFree来申请/释放内存

转 http://blog.csdn.net/gaoxiaowei/article/details/5701789


从网上看来的说法:
The thing is that COM (actually the RPC runtime library, but it's easier to blame COM) has an additional requirement for [out] pointers.  This requirement is that if the type of an [out] parameter isn't a scalar quantity (in other words if it's a structure or anything more complicated than a int or float), then the memory pointed to by the [out] parameter needs to be allocated either by MIDL_user_allocate (for RPC) orCoTaskMemAlloc(for COM).

也就是说,如果需要调用COM接口,并且接口中有[out]的参数,且类型不是整形或浮点数之类的基本数据类型,就需要调用CoTaskMemAlloc来申请这块内存,并使用完毕后调用CoTaskMemFree来释放。

你可能感兴趣的:(关于什么时候使用CoTaskMemAlloc/CoTaskMemFree来申请/释放内存)