CoTaskMemFree的用法

来源:互联网 发布:家具erp 知乎 编辑:程序博客网 时间:2024/06/06 05:01

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) or CoTaskMemAlloc (for COM).

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