Export (0) Print
Expand All

xlGetInstPtr

Office 2013

Last modified: July 01, 2011

Applies to: Excel 2013 | Office 2013 | Visual Studio

Returns the instance handle of the instance of Microsoft Excel that is currently calling a DLL.

Excel4(xlGetInstPtr, LPXLOPER pxRes, 0);Excel12(xlGetInstPtr, LPXLOPER12 pxRes, 0);

This function has no arguments.

The instance handle (xltypeBigData) will be in the val.bigdata.h.hdata field.

This function can be used to distinguish between multiple running instances of Excel that are calling the DLL.

This function returns a correct value with both 32-bit and 64-bit versions of Excel. It was introduced in Excel 2010 as an extension to the xlGetInst function, which works correctly only with 32-bit versions of Excel.

This function works correctly when it is called by using both the Excel4 and Excel12 varieties of the API callback functions, because both XLOPER and XLOPER12 have the same structure that supports the xltypeBigData value type.

The following example compares the instance of the last copy of Excel that called it to the current copy of Excel that called it. If they are the same, it returns 1; if not, it returns 0; if the function fails, it returns -1. This sample works with both 32-bit and 64-bit versions of Excel.

\SAMPLES\EXAMPLE\EXAMPLE.C

short WINAPI xlGetInstPtrExample(void)
{
    XLOPER12 xRes;
    static HANDLE hOld = 0;
    short iRet;

    if (Excel12(xlGetInstPtr, &xRes, 0) != xlretSuccess)
    iRet = -1;
    else
    {
    HANDLE hNew;

    hNew =  xRes.val.bigdata.h.hdata;
    if (hNew != hOld)
    iRet = 0;
    else
    iRet = 1;
    hOld = hNew;
    }

    return iRet;
}
Show:
© 2015 Microsoft