ispiro
ispiro

Reputation: 27713

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?

Upvotes: 1

Views: 455

Answers (1)

Hans Passant
Hans Passant

Reputation: 942099

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().

Upvotes: 3

Related Questions