Share via


xlGetInst

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

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

Excel4(xlGetInst, LPXLOPER pxRes, 0); /* returns low part only */
Excel12(xlGetInst, LPXLOPER12 pxRes, 0); /* returns full handle */

Parameters

This function has no arguments.

Property Value/Return Value

The instance handle (xltypeInt) will be in the val.w field.

Remarks

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

When you are calling this function using Excel4 or Excel4v, the returned XLOPER integer variable is a signed 16-bit short int. This is only capable of containing the low 16 bits of the 32-bit Windows handle. In Microsoft Office Excel 2007, the integer variable of the XLOPER12 is a signed 32-bit int and therefore contains the entire handle, removing the need to iterate all open windows.

Example

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.

\SAMPLES\EXAMPLE\EXAMPLE.C

short WINAPI xlGetInstExample(void)
{
    XLOPER xRes;
    static HANDLE hOld = 0;
    int iRet;

    Excel4(xlGetInst, (LPXLOPER)&xRes, 0);

    if((unsigned int)xRes.val.w != hOld)
        iRet = 0;
    else
        iRet = 1;

    hOld = xRes.val.w;

    return iRet;
}

See Also

Reference

xlGetHwnd

Concepts

C API Functions That Can Be Called Only from a DLL or XLL