Take the 2-minute tour ×

How do you define a non-default constructor for a COM object in Visual C++?

Is such a thing even possible?

Or do you have to construct a default object and use an init(params) method to configure it?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

COM coclasses implemented in C++ cannot have a constructor that takes an argument. The CoCreateObject() function, the primary way to create an instance of a coclass, doesn't have any way to pass arguments. Same with IClassFactory::CreateInstance(), the underlying method.

So yes, not possible, you'll need an Initialize() method. And the code to verify that it was called, E_UNEXPECTED with a decent IErrorInfo message is boilerplate.

share|improve this answer
add comment

Your Answer


