This example, shown in Microsoft® Visual C++®, displays a message when executed. The text of the message is provided by a property you add. To implement this example, do the following:
Create a custom task framework using the ATL custom task basic template provided with Microsoft SQL Server™ 2000. Name the component DTSTskPropIcon and the task class GenMessage. Change the Type field in ATL Object Wizard from GenMessage Class to Generate Message Task. For more information about using the basic template, see Building a Custom Task from the ATL Custom Task Basic Template.
Add the Message property to the custom task.
To add the Message property
Select a suitable icon for the task for which you have an .ico file.
To add an icon
When you select a file, the icon editor is displayed. If you make changes to the icon, you must edit both the 16x16 and 32x32 bit images.
This procedure makes a local copy of the icon file in the project directory whether or not you made changes in the icon editor.
Add the following code segments to the framework files:
The declaration goes in the private section for the CGenMessage class, in file GenMessage.h.
Immediately after the lines:
BSTR m_bstrName;
BSTR m_bstrDescription;
insert the line:
BSTR m_bstrMessage;
The Message property must be initialized to a valid value. This is done in the task class constructor in GenMessage.cpp.
At the end of the task class constructor (before the right curly bracket):
CGenMessage::CGenMessage()
add this line:
m_bstrMessage = SysAllocString( OLESTR("") );
The allocated string must be released before the custom task is removed from memory. This is done in the class destructor, also in GenMessage.cpp.
At the end of the destructor (before the right curly bracket):
CGenMessage::~CGenMessage()
add this line:
if (m_bstrMessage) SysFreeString(m_bstrMessage);
The message is displayed in the Execute function in file GenMessage.cpp. The Description property is displayed in the message caption and the Message property is displayed in the message text.
Replace the // TODO comment in CGenMessage::Execute with the following code:
MessageBox( NULL, OLE2T( (LPOLESTR)m_bstrMessage ),
OLE2T( (LPOLESTR)m_bstrDescription ), MB_ICONINFORMATION );
To build the project, click Build DTSTskPropIcon.dll on the Build menu. Refresh the DTS cache, if necessary. For more information about preparing the custom task for execution, see Implementing and Testing a DTS Custom Task.
Open DTS Designer and drag the icon for this task onto the design sheet. When the default property grid is displayed, enter or change the values of the Description and Message properties. The new value for Description will be used for the icon title.
Note Do not change the Name property. If you do, DTS Designer will generate an error when it is unable find the task using the original name.
When you execute the package, a message box will appear with the Description property as its caption and the Message property as its text.