void RegisterExcelFunction (LPXLOPER xDLL, const char* xllFunctionName, const char* excelFunctionName, const char* pxTypeText, char* pxFuncDescription, char* excelCategory, char* argumentDesc) { const int argumentCount = 10; // [0]pxModuleText, [1]pxProcedure, [2]pxTypeText // [3]pxFunctionText, [4]pxArgumentText // [5]pxMacroType, [6]pxCategory, [7]pxShortcutText, [8]pxHelpTopic, [9]pxFunctionHelp static LPXLOPER input[argumentCount]; input[0] = (LPXLOPER FAR) xDLL; input[1] = (LPXLOPER FAR) XLUtil::MakeExcelString2(xllFunctionName); input[2] = (LPXLOPER FAR) XLUtil::MakeExcelString2(pxTypeText); input[3] = (LPXLOPER FAR) XLUtil::MakeExcelString2(excelFunctionName); input[4] = (LPXLOPER FAR) XLUtil::MakeExcelString2(argumentDesc); input[5] = (LPXLOPER FAR) XLUtil::MakeExcelString2("1"); input[6] = (LPXLOPER FAR) XLUtil::MakeExcelString2(excelCategory); input[7] = (LPXLOPER FAR) XLUtil::MakeExcelString3(0); input[8] = (LPXLOPER FAR) XLUtil::MakeExcelString3(0); input[9] = (LPXLOPER FAR) XLUtil::MakeExcelString2(pxFuncDescription); int result = Excel4v (xlfRegister, NULL, argumentCount, (LPXLOPER FAR*)input); for ( int i = 1; i < argumentCount; i++) { XLUtil::FreeContents ( input[i] ); free ( input[i] ); } }
G_MODULE_EXPORT int far _cdecl Excel4(int xlfn, void* operRes, int count, ...) { void **opers=(void**)alloca(count*sizeof(void*)); va_list arg_list; int i; va_start(arg_list,count); for (i=0; i<count; ++i) opers[i]=va_arg(arg_list,void*); va_end(arg_list); return Excel4v(xlfn,operRes,count,(void**)opers); }
static void registerAllFunctions(void){ XLOPER xlopers[30]; XLOPER *excel4vArgs[30]; XLOPER xlRet; unsigned long i,j; const unsigned long n = sizeof(registration_info)/sizeof(Excel4RegistrationInfo); for (i=0;i<30;++i){ excel4vArgs[i]=xlopers+i; } Excel4(xlGetName, excel4vArgs[0], 0); for (i=0;i<n;++i){ for (j=0;j<29&&NULL!=registration_info[i][j];++j){ excel4vArgs[1+j]->xltype=xltypeStr; excel4vArgs[1+j]->val.str=pascal_string_from_c_string(registration_info[i][j]); } Excel4v(xlfRegister, &xlRet, j+1, excel4vArgs); for (j=0;j<29&&NULL!=registration_info[i][j];++j){ g_free(excel4vArgs[1+j]->val.str); } } }
/* * Requests the function list from the server and registers each function with excel. */ void RegisterFunctions(LPXLOPER xDLL, int index) { if(!InitProtocol(index)) { return; } // Ask the server for a list of functions and register them LPXLOPER farr = g_protocol[index]->execute(AF_GET_FUNCTIONS, false, 0); int t = farr->xltype & ~(xlbitXLFree | xlbitDLLFree); int rows = farr->val.array.rows; int cols = farr->val.array.columns; if(farr != NULL && t == xltypeMulti && cols == 1 && rows > 0) { for(int i = 0; i < rows; i++) { LPXLOPER earr = &farr->val.array.lparray[i]; t = earr->xltype & ~(xlbitXLFree | xlbitDLLFree); if(t != xltypeMulti) continue; char* functionName = XLMap::getString(earr, "functionName"); char* functionText = XLMap::getString(earr, "functionText"); char* argumentText = XLMap::getString(earr, "argumentText"); char* category = XLMap::getString(earr, "category"); char* shortcutText = XLMap::getString(earr, "shortcutText"); char* helpTopic = XLMap::getString(earr, "helpTopic"); char* functionHelp = XLMap::getString(earr, "functionHelp"); LPXLOPER argumentHelp = XLMap::get(earr, "argumentHelp"); bool isVolatile = XLMap::getBoolean(earr, "isVolatile"); if(functionName != NULL) { char tmp[MAX_PATH]; sprintf(tmp, "FS%d", g_functionCount); char* argHelp[100]; int argHelpCount=0; if(argumentHelp != NULL) { for(int j = 0; j < argumentHelp->val.array.rows; j++) { argHelp[argHelpCount++] = argumentHelp->val.array.lparray[j].val.str; } argHelp[argHelpCount++] = ""; } int size = 10 + argHelpCount; static LPXLOPER input[20]; input[0] = (LPXLOPER FAR) xDLL; input[1] = (LPXLOPER FAR) XLUtil::MakeExcelString2(tmp); input[2] = (LPXLOPER FAR) XLUtil::MakeExcelString2(isVolatile ? "RPPPPPPPPPPPPPPPPPPPP!" : "RPPPPPPPPPPPPPPPPPPPP"); input[3] = (LPXLOPER FAR) XLUtil::MakeExcelString3(functionText == NULL ? functionName : functionText); input[4] = (LPXLOPER FAR) XLUtil::MakeExcelString3(argumentText); input[5] = (LPXLOPER FAR) XLUtil::MakeExcelString2("1"); input[6] = (LPXLOPER FAR) XLUtil::MakeExcelString3(category); input[7] = (LPXLOPER FAR) XLUtil::MakeExcelString3(shortcutText); input[8] = (LPXLOPER FAR) XLUtil::MakeExcelString3(helpTopic); input[9] = (LPXLOPER FAR) XLUtil::MakeExcelString3(functionHelp); for(int j = 0; j < argHelpCount && j < 20; j++) { input[10 + j] = (LPXLOPER FAR) XLUtil::MakeExcelString3(argHelp[j]); } int res = Excel4v(xlfRegister, 0, size, (LPXLOPER FAR*) input); for(int j = 1; j < size; j++) { free(input[j]); } if(res == 0) { memcpy(tmp, &functionName[1], functionName[0]); tmp[functionName[0]] = 0; g_functionServer[g_functionCount] = index; g_functionNames[g_functionCount++] = strdup(tmp); if(g_debugLogging) { char* provider = g_serverSections[index]; if(provider) Log::Debug("Registered function (%d) %s for server %s", g_functionCount, tmp, provider); else Log::Debug("Registered function (%d) %s", g_functionCount, tmp); } } } } XLUtil::FreeContents(farr); } }