When you added the MinMaxShipping object to the MinMaxShip project in Step 2: Adding an Object, the Pipeline Component Wizard added the definition and implementation files for this object to the MinMaxShip project. These files, the MinMaxShipping.h and MinMaxShipping.cpp files define and partially implement the necessary pipeline interfaces: IPipelineComponent, IPipelineComponentDescription, ISpecifyPropertyPages, and IPersistStreamInit.
In addition, the Pipeline Component Wizard added to the MinMaxShipping.h file a definition for IMinMaxShipping, an interface that inherits from IDispatch, and through which the MinMaxShip component exposes the properties that it supports.
The MinMaxShip component supports two properties: MinShipping and Percentage. In this step, you will add these properties to the component's IMinMaxShipping interface so that they can be set or retrieved by a scripting language client.
A dialog box is displayed in which you can specify the name and data type of the property.
The dialog now looks like this.
If you open up the MinMaxShipping.cpp file, you will notice that Visual C++ has made a few modifications to your component class. This class now includes the following function stubs:
STDMETHODIMP CMinMaxShipping::get_MinShipping(long *pVal)
{
return S_OK;
}
STDMETHODIMP CMinMaxShipping::put_MinShipping(long newVal)
{
return S_OK;
}
STDMETHODIMP CMinMaxShipping::get_Percentage(float *pVal)
{
return S_OK;
}
STDMETHODIMP CMinMaxShipping::put_Percentage(float newVal)
{
return S_OK;
}
To make these methods functional, declare variables to store these property values internally within the CMinMaxShipping class. In the MinMaxShipping.h file, which contains the class definition for the MinMaxShip component, declare the following variables:
CComVariant m_varMinShipping;
CComVariant m_varPercentage;
You can enable the functions above as follows, taking advantage of the fact that CComVariant overloads the assignment (=) operator:
STDMETHODIMP CMinMaxShipping::get_MinShipping(long *pVal)
{
*pVal = V_I4(&m_varMinShipping);
return S_OK;
}
STDMETHODIMP CMinMaxShipping::put_MinShipping(long newVal)
{
m_varMinShipping = newVal;
return S_OK;
}
STDMETHODIMP CMinMaxShipping::get_Percentage(float *pVal)
{
*pVal = m_varPercentage;
return S_OK;
}
STDMETHODIMP CMinMaxShipping::put_Percentage(float newVal)
{
m_varPercentage = newVal;
return S_OK;
}
Given the data type of the arguments passed to these methods (long and float, respectively), you may wonder why one would use the CComVariant class to store their values. The reason for this is that the CComVariant class supports methods that are particularly conducive to storing the property values in a stream (Step 4: Saving Properties).
To test the setting of these properties, you can create a debug executable in Visual Basic. In this executable, use the CreateObject function to create an instance of the MinMaxShipping object using its Prog ID (MinMaxShip.MinMaxShip), and initialize the properties to some value. Specify this executable as the debug executable for the project, and set a breakpoint in any of the method implementations previously listed:
Dim objMinShipping
Set objMinShipping = CreateObject("MinShipping.MinShipping.1")
objMinShipping.Percentage = .05
objMinShipping.MinShipping = 1.00
Debug.Print objMinShipping.Percentage
Debug.Print objMinShipping.MinShipping