How to prevent coclass implementations from being used in the ATL type library

I am creating an ATL type library with a class type of factory. Something like that:

[ 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;
}

Then the user can get an instance of the class that implements the interface INumberthrough NumberFactory.

This works well, but I cannot figure out how to define and instantiate the ATL objects returned by the method NumberFactory.GetNumber(). If I define numbers in IDL like this:

[ uuid(...) ]
coclass One {
    [default] interface INumber;
}

The component Onecan be created by the user. But I would like to restrict it, so the only way to get an instance of the class Oneis to call NumberFactory.GetNumber("One").

, : IDL, One, One NumberFactory coclass INumber One ?

, - , ATL , ?

+3
2
  • CoClass IDL
  • CoClass ( OBJECT_ENTRY_AUTO)
  • CNumber
  • GetNumber (...) :
*pVal = new CComObject<CNumber>();  
(*pVal)->AddRef();

, CoClass , factory , .

+4

-, ... ( ), , ...

:

  • noncreatable IDL
  • OBJECT_ENTRY_AUTO ATL (, )

. MSDN: http://msdn.microsoft.com/en-us/library/4tc639ss.aspx

+1

Source: https://habr.com/ru/post/1713709/


All Articles