简体   繁体   中英

Do I need to DeleteObject to dispose of an HBITMAP* when using [ComImportAttribute()]?

From MSDN about IShellItemImageFactory::GetImage :

It is the responsibility of the caller to free this retrieved resource through DeleteObject when it is no longer needed.

My question is:

I'm using the IntPtr in an IShellItemImageFactory.GetImage call where the IShellItemImageFactory is decorated with [ComImportAttribute()] . Do I still need to call DeleteObject , or will that cause trouble when the CLR(?) will try deleting it as part of the Factory ?

The CLR will never automatically release an IntPtr. It cannot possibly know what specific function needs to be called to release the pointer. It is entirely up to you to pinvoke DeleteObject().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM