This function checks the amount of space left on the stack.
Returns the number of bytes (xltypeInt) remaining on the stack.
Excel4(xlStack, LPXLOPER pxRes, 0);
This function has no arguments.
Microsoft Excel 97 has quite a bit more stack space than previous versions. This has caused a problem, since the amount of stack space is returned as a signed integer. This means that xlStack can return a value between -32767 and 32768. The stack space in Microsoft Excel 97 typically exceeds 40K, which causes xlStack to report a value like -12076. To obtain the correct value, cast the returned value to an unsigned short.
Microsoft Excel has a limited amount of space on the stack, and you should take care not to overrun this space. First, never put large data structures on the stack. Make as many local variables as possible static. Avoid calling functions recursively, because that will quickly fill up the stack.
If you suspect that you are overrunning the stack, call this function frequently to see how much stack space is left.
If you desperately need more stack space than the 44K or so that you normally get, you can use the Windows functions SwitchStackTo and SwitchStackBack.
The following example displays an alert message containing the amount of stack space left.
\SAMPLES\EXAMPLE\EXAMPLE.C
short int WINAPI xlStackExample(void)
{
XLOPER xRes;
XLOPER xAlert;
Excel4(xlStack, (LPXLOPER)&xRes, 0);
xAlert.xltype = xltypeNum;
// Cast to an unsigned short first to get rid of the overflow problem
xAlert.val.num = (double)(unsigned short) xRes.val.w;
Excel4(xlcAlert, 0, 1, (LPXLOPER)&xAlert);
return 1;
}