Excel12 and Excel12v
There are two API functions that enable you to interact with Excel.
These are both callback functions that allows the DLL to call Excel.
The only difference between them is the number of arguments.
Excel12 - takes a variable number of arguments. The maximum is 255.
Excel12v - takes 4 arguments, with the last one being a variable sized array.
Excel12 and Excel12v ensure backwards compatibility with Excel 11 (2003) and earlier.
Excel12
uses UNICODE based strings
int Excel12(int iFunction,
xloper12 *pxReturnValue,
int iCount,
xloper12 *pxArgument1,
..,
xloper12 *pxArgument255)
iFunction - The number corresponding to a pre-defined function or command.
pxReturnValue - A pointer that will hold the result.
iCount - The number of arguments that are being passed in.
pxArgument1 - The first argument. Passed as a pointer.
pxArgument255 - The last argument. Passed as a pointer.
Excel12v
int Excel12v(int iFunction,
xloper12 *pxReturnValue,
int iCount,
xloper12 *pxArguments[])
iFunction - The number corresponding to a pre-defined function or command.
pxReturnValue - A pointer that will hold the result.
iCount - The number of arguments that are being passed in.
pxArguments - The array of arguments. They are all passed as pointers.
XLOPER12 data type
This is a multi-type data structure that can represent any type of worksheet data type.
XLOPER12 vs LPXLOPER12
In most cases the prototype is written as:
int Excel12v(int iFunction, xloper12 *pRetVal, int count, xloper12 *args[]);
but sometimes it is written as:
int Excel12v(int iFunction, LPXLOPER12 operRes, int count, xloper12 *args[]);
This is just to represent that the argument is a pointer without having to include the asterisk (*)
Return Values
What is returned will indicate whether the call has been successful or not.
If a non-zero is returned then the function was not successful.
If zero is returned (or xlretSuccess) then the function might have been successful.
You always need to check the "pxReturnValue"
| 0 | xlretSuccess | Called successfully but you need to check the return value |
| 1 | xlretAbort | The macro that has been stopped by the user or the system |
| 2 | xlretInvX1fn | The function is not recognised, not supported or has the wrong context |
| 4 | xlretInvCount | The number of arguments is wrong |
| 8 | xlretInvXloper | One or more of the arguments passed in are not valid |
| 16 | xlretStackOvfl | Excel's pre-call stack check indicates a possibility that the stack might overflow |
| 32 | xlretFailed | The command failed or unable to allocate enough memory |
| 64 | xlretUncalced | A worksheet function tries to access cells that have not yet been recalculated |
| 128 | xlretNotThreadSafe | Trying to call a not thread safe method from a function indicated as thread safe |
Excel Data Types
Excel will pass arguments and accepr return values for the following data types.
| Data Type | Type | |
| unsigned short * | String | UNICODE wide char string, length prepended |
| unsigned short * | String | UNICODE wide char string, null prepended |
| unsigned char * | String | ASCII byte string, length prepended |
| signed char * | String | ASCII byte string, null terminated |
| double | Number | |
| double * | Number | |
| signed long int | Number | 32-bit |
| signed long int * | Number | 32-bit |
| signed short int | Number | 16-bit. can be used for bool |
| signed short int * | Number | 16-bit |
| unsigned short int | Number | DWORD = wchar_t |
Data types such as bool, char and float are not supported.
If an Excel worksheet function cannot convert an input value to the necessary type, it will return #VALUE!
Excel Events
The C API command functions are xlcOnData, xlcOnDoubleclick, xlcOnEntry, xlcOnKey, xlcOnRecalc, xlcOnWindow, xlcOnTime
Excel4
Excel 2003 and earlier.
uese the XLOPER data structure
uses ASCII based strings
An XLL is only loaded once per session
These can be browsed to from the Excel add-ins dialog box ?
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrevNext