XLL+ Class Library (6.3)

Using an extended type

Selecting an extended type

If we now return to the XLL+ Function Wizard, we will find that the Date type has been added to the list of available argument types.

Code generated for an extended type

Let us examine the code that is generated for a date type:

CopyC++
CXlOper* DateFn_Impl(CXlOper& xloResult, double ValueDate_op)
{
    // Input buffers 
    long ValueDate;
    // Validate and translate inputs
    XlReadScalarEx(ValueDate_op, ValueDate, psl::DateConverter(), L"ValueDate");
    // End of generated code

The validation function is slightly different from what we have seen before.

  1. The function is named XlReadScalarEx instead of XlReadScalar.
  2. The function takes an extra argument, a newly created instance of psl::DateConverter.

You will recall that this was the value of the extended type's ConverterType property.

The other change is that we now have a local variable ValueDate of the reqired date type, long.

When the ValueDate argument is validated at run-time, we see some new behavior. If the argument is a number less than 30000, we get the error result:

#ERROR: Expected date for ValueDate

Arrays of extended types

We can just as easily handle arrays of extended type values. For example, we could have a vector input PaymentDates:

This code is generated:

CopyC++
// Input buffers 
std::vector<long> PaymentDates;
// Validate and translate inputs
XlReadVectorEx(*PaymentDates_op, PaymentDates, psl::DateConverter(), 
    L"PaymentDates", XLA_TRUNC_ONEMPTY|XLA_TRUNC_ONBLANK);
// End of generated code

The local variable PaymentDates is of type std::vector<long>, as is required.

Next, we will examine the converter class, since that is where all the work appears to be happening.

Next: Converter class >>