Once your basic project is defined, you need to add a COM object that can communicate with the Tool Palette framework. Since your project uses ATL, the easiest way to add COM objects is with Visual Studio ATL wizard. Consult the Microsoft documentation for guidance on using this wizard.
The ATL wizard creates several new files and adds them to your project. These files create an ISimpleTool interface definition and a CSimpleTool coclass.
Note that the CSimpleTool coclass derives from the following standard ATL classes:
In the next procedure, you change this derivation to use the AcadToolImpl class.
CSimpleTool now derives only from CComCoClass.
These two additional LPCTSTR arguments also are required by the AcadToolImpl template:
In order to make this information available to both the declaration and the implementation, declare them as global variables.
TCHAR szSimpleToolName[256] = “Simple Tool”;
TCHAR szSimpleToolImage[256] = “IDB_TOOL1”;
extern TCHAR szSimpleToolName[256];
extern TCHAR szSimpleToolImage[256];
Declaring these globals in the implementation file and referencing them externally in the header file helps to avoid MSVC linker error LNK2005.
The final coclass derivation should match the following:
class ATL_NO_VTABLE CSimpleTool : public CComCoClass<CSimpleTool, &CLSID_SimpleTool>, public AcadToolImpl<CSimpleTool, ISimpleTool, &CLSID_SimpleTool, szSimpleToolName, szSimpleToolImage>
One final change must be made to ATL's default implementation. You do not need the ATL COM map when you derive from AcadToolImpl. The AcadToolImpl class handles outgoing interfaces.
Your coclass now is derived correctly, with unwanted ATL code removed. However, you need to make a few additions to support AcadToolImpl before you can compile and build the project.
AcadToolImpl provides access to Property Inspector interfaces such as IAcPiPropertyDisplayImpl and IPerPropertyDisplay. This implementation makes it easy for you to adapt the Properties palette UI to your application's needs. Even if you do not intend to use this feature, however, you must provide a small amount of supporting code.
To finish the skeleton application
BEGIN_PERPROPDISPLAY_MAP2() END_PERPROPDISPLAY_MAP2()
BEGIN_FLYOUT_SPECIFIC_MAP() END_FLYOUT_SPECIFIC_MAP()
virtual HINSTANCE GetResourceInstance() { return _AtlBaseModule.GetResourceInstance(); }