I am building an ATL type library with a type of class factory. Something sorta like this:
[ object, uuid(...), ... ]
interface INumber : IDispatch {
[propget, id(0)] HRESULT Value([out, retval] LONG* pVal);
}
[ object, uuid(...), ... ]
interface INumberFactory : IDispatch {
[id(1)] HRESULT GetNumber([in] BSTR numberName, [out, retval] INumber* pVal);
}
[ uuid(...) ]
coclass NumberFactory {
[default] interface INumberFactory;
}
The user can then get an instance of a class that implements the INumber
interface through the NumberFactory
.
This works well, but I cannot figure out how to define and instantiate the ATL objects that are returned through the NumberFactory.GetNumber()
method. If I define the numbers in the IDL like this:
[ uuid(...) ]
coclass One {
[default] interface INumber;
}
the One
coclass can be instantiated by the user. But I would like to restrict it so the only way you can get an instance of the One
coclass is by calling NumberFactory.GetNumber("One")
.
So my question is: How should the IDL be written so the user cannot instantiate One
, but still be able to instantiate One
from within then NumberFactory
coclass and return the INumber
interface of One
to the user?
Additionally, is there anything special that must be done in the ATL side of things in order for this to work?