Under the hood, Excel "dates" are doubles, and the XLOPER structure appears to have no sense of date but merely xltypeNum (unlike Variants in VBA).
I have a straightforward XLL with a function that returns the current date as an LPXLOPER and requires no arguments (type "P"). I am using "P" rather than "B" as the return value because I have other functions that typically return dates but could also return errors.
DLLEXPORT LPXLOPER WINAPI epToday()
static XLOPER xResult;// Return value
xResult.xltype = xltypeNum;
xResult.val.num = ExcelDateForToday(); //A function that returns a double for today's date
The calling spreadsheet shows a number for the return value (eg 40303). In the same manner that the built-in function TODAY() does, I would like to be able to instruct Excel to treat the double value it has returned as a date. Exists a method for achieving this?
Should I use a callback to modify the format for the caller cell since =TODAY() converts the cell's NumberFormat to "Date"? Excel appears to be doing this, for instance, if I recalculate a cell using the =TODAY() function, Excel will once more set the NumberFormat to Date.