예제 #1
0
// Excel calls xlAutoRegister12 if a macro sheet tries to register
// a function without specifying the type_text argument.
__declspec(dllexport) LPXLOPER12 WINAPI xlAutoRegister12(LPXLOPER12 pxName)
{
       static XLOPER12 xDLL, xRegId;
       int i;

       xRegId.xltype = xltypeErr;
       xRegId.val.err = xlerrValue;
 
       for (i = 0; i < g_rgNumUDFs; i++)
       {
              if (!lpwstricmp(g_rgUDFs[i][0], pxName->val.str))
              {
                     Excel12f(xlfRegister, 0, 1 + g_rgUDFdata,
                             (LPXLOPER12) &xDLL,
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][0]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][1]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][2]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][3]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][4]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][5]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][6]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][7]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][8]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][9]),
                             (LPXLOPER12) TempStr12(g_rgUDFs[i][10])
                             );
 
                     // Free the oper returned by Excel.
                     Excel12f(xlFree, 0, 1, (LPXLOPER12) &xDLL);
                     return(LPXLOPER12) &xRegId;
              }
       }
 
       return(LPXLOPER12) &xRegId;
}
예제 #2
0
// Excel calls xlAutoRegister12 if a macro sheet tries to register
// a function without specifying the type_text argument.
__declspec(dllexport) LPXLOPER12 WINAPI xlAutoRegister12(LPXLOPER12 pxName)
{
    static XLOPER12 xDLL, xRegId;
    int i;

    /*
    ** This block initializes xRegId to a #VALUE! error first. This is done in
    ** case a function is not found to register. Next, the code loops through the
    ** functions in rgFuncs[] and uses lpstricmp to determine if the current
    ** row in rgFuncs[] represents the function that needs to be registered.
    ** When it finds the proper row, the function is registered and the
    ** register ID is returned to Microsoft Excel. If no matching function is
    ** found, an xRegId is returned containing a #VALUE! error.
    */

    xRegId.xltype = xltypeErr;
    xRegId.val.err = xlerrValue;

    for (i = 0; i < rgWorksheetFuncsRows; i++) 
    {
        if (!lpwstricmp(rgWorksheetFuncs[i][0], pxName->val.str)) 
        {
            Excel12f(xlGetName, &xDLL, 0);

            Excel12f(xlfRegister, 0, 4,
                (LPXLOPER12)&xDLL,
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][0]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][1]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][2]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][3]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][4]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][5]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][6]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][7]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][8]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][9]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][10]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][11]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][12]),
                (LPXLOPER12)TempStr12(rgWorksheetFuncs[i][13]));
                
            /* Free the XLL filename */
            Excel12f(xlFree, 0, 1, (LPXLOPER12)&xDLL);

            return (LPXLOPER12)&xRegId;
        }
    }

    //Word of caution - returning static XLOPERs/XLOPER12s is not thread safe
    //for UDFs declared as thread safe, use alternate memory allocation mechanisms

    return (LPXLOPER12)&xRegId;
}