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?
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?
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.