How do I create classes in an ATL project?

I am writing an ATL project and I am wondering how can I create classes here. Right now I have one class created by Add / Class / ATL Simple Object . I want to divide it into smaller classes, but the method from these classes should use CComPtrand have CComPtras an argument. I cannot create a β€œsimple” C ++ class because I do not CComPtr.

Should I create ATL classes using the ATL Simple Object Wizard and then use the interface for this class to call methods. Like here:

CComPtr<ITestAtlClass> tptr;
tptr.CoCreateInstance(CLSID_TestAtlClass);
tptr->test();

And should I add all public methods using Class View / ITestAtlClass / Add / Add Method ? What about the constructors? Do I need to initialize my class only by properties (and add them through Class View / ITestAtlClass / Add / Add property )? And pass each com object using the IUnknown interface?

Can someone tell me how this should be done in the ATL project. I will use these smaller classes internally (no one will create these classes outside my DLL) to make my code more readable.

+5
source share
1 answer

, CComPtr ++. ?

:

  • ++, , COM.
  • ATL CComObject<> , CoCreateInstance .

, , , , .

COM- ATL CVehicle, CComObjectRootEx<> , :

   CComObject<CVehicle>* vehicle = NULL;
   CComObject<CVehicle>::CreateInstance(&vehicle);

   vehicle->AddRef();

   // To get at any of its interfaces, use:
   CComPtr<ICar> car = 0;
   vehicle->QueryInterface(&car);

   // And to delete object, use:
   vehicle->Release();

CComObject<>, . CComObjectStack<>, .

, . , , CComPtr, , .

+8

All Articles