semicolon
semicolon

Reputation: 65

Do I need to initialize COM before using IStream with GDI+ Bitmap::FromStream()?

I am using the GDI+ function Bitmap::FromStream() to load a PNG resource, following the example provided in this article.

The Bitmap::FromStream() function requires an IStream as its first argument. Since IStream is a COM interface, and my knowledge of COM programming is limited, I want to clarify:

Any insight into whether COM initialization is necessary in this context would be greatly appreciated.


Edit:

This question is not a duplicate.

In the other question, the application fails outright without calling CoInitialize(), and the focus is on understanding why it is required.

However, in my case, the application works without explicitly initializing COM, and my concern is whether this is safe or if it might lead to issues under certain conditions. My question seeks clarification on whether explicit COM initialization is necessary when using COM interfaces and the potential implications of skipping the initialization.

Upvotes: 3

Views: 129

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597906

You do not need to initialize COM if you define your own class that implements a COM interface for use in your own code.

You do need to initialize COM if you create a COM object via a system factory, or pass around your object outside of your exe.

For example, if you use CreateStreamOnHGlobal() or SHCreateMemStream() to create the IStream object then you should initialize COM first. If you implement the IStream in your own class then you don't need to.

Upvotes: 2

Related Questions