Skip to content

Commit 79f5719

Browse files
authored
Merge pull request #32 from rxxg/master
Allow up to 30 arguments in function calls
2 parents f542e5a + 5af010a commit 79f5719

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

xlloop-addin/src/XLLoop.cpp

+40-28
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ static int g_functionCount = 0;
4343
// The mapping of function index to server index
4444
static int g_functionServer[MAX_FUNCTIONS];
4545

46+
// The maximum number of arguments we allow in a function call
47+
#define MAX_ARGUMENTS 30
48+
4649
// Our standard error message
4750
static XLOPER g_errorMessage;
4851

@@ -196,18 +199,18 @@ void RegisterFunctions(LPXLOPER xDLL, int index)
196199
argHelp[argHelpCount++] = "";
197200
}
198201
int size = 10 + argHelpCount;
199-
static LPXLOPER input[20];
202+
static LPXLOPER input[10 + MAX_ARGUMENTS];
200203
input[0] = (LPXLOPER FAR) xDLL;
201204
input[1] = (LPXLOPER FAR) XLUtil::MakeExcelString2(tmp);
202-
input[2] = (LPXLOPER FAR) XLUtil::MakeExcelString2(isVolatile ? "RPPPPPPPPPPPPPPPPPPPP!" : "RPPPPPPPPPPPPPPPPPPPP");
205+
input[2] = (LPXLOPER FAR) XLUtil::MakeExcelString2(isVolatile ? "RPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP!" : "RPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
203206
input[3] = (LPXLOPER FAR) XLUtil::MakeExcelString3(functionText == NULL ? functionName : functionText);
204207
input[4] = (LPXLOPER FAR) XLUtil::MakeExcelString3(argumentText);
205208
input[5] = (LPXLOPER FAR) XLUtil::MakeExcelString2("1");
206209
input[6] = (LPXLOPER FAR) XLUtil::MakeExcelString3(category);
207210
input[7] = (LPXLOPER FAR) XLUtil::MakeExcelString3(shortcutText);
208211
input[8] = (LPXLOPER FAR) XLUtil::MakeExcelString3(helpTopic);
209212
input[9] = (LPXLOPER FAR) XLUtil::MakeExcelString3(functionHelp);
210-
for(int j = 0; j < argHelpCount && j < 20; j++) {
213+
for(int j = 0; j < argHelpCount && j < MAX_ARGUMENTS; j++) {
211214
input[10 + j] = (LPXLOPER FAR) XLUtil::MakeExcelString3(argHelp[j]);
212215
}
213216
int res = Excel4v(xlfRegister, 0, size, (LPXLOPER FAR*) input);
@@ -228,7 +231,7 @@ void RegisterFunctions(LPXLOPER xDLL, int index)
228231
Log::Debug("Registered function (%d) %s", g_functionCount, tmp);
229232
}
230233
}
231-
}
234+
}
232235
}
233236

234237
XLUtil::FreeContents(farr);
@@ -252,15 +255,15 @@ void RegisterServer(LPXLOPER xDLL, int index)
252255
if(includeGeneric) {
253256
char fsExecuteFn[MAX_PATH];
254257
sprintf(fsExecuteFn, "FSExecute%d", index);
255-
XLUtil::RegisterFunction(xDLL, fsExecuteFn, "RCPPPPPPPPPPPPPPPPPPPP",
258+
XLUtil::RegisterFunction(xDLL, fsExecuteFn, "RCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",
256259
function, NULL, "1", category, NULL, NULL, NULL, NULL);
257260
}
258261

259262
// Register execute function - volatile version (if requested)
260263
if(includeVolatile) {
261264
char fsExecuteVolFn[MAX_PATH];
262265
sprintf(fsExecuteVolFn, "FSExecuteVolatile%d", index);
263-
XLUtil::RegisterFunction(xDLL, fsExecuteVolFn, "RCPPPPPPPPPPPPPPPPPPPP!",
266+
XLUtil::RegisterFunction(xDLL, fsExecuteVolFn, "RCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP!",
264267
volatileFunction, NULL, "1", category, NULL, NULL, NULL, NULL);
265268
}
266269

@@ -296,8 +299,8 @@ void ParseProviders(char* providers)
296299
}
297300

298301
#ifdef __cplusplus
299-
extern "C" {
300-
#endif
302+
extern "C" {
303+
#endif
301304

302305
__declspec(dllexport) int WINAPI xlAutoOpen(void)
303306
{
@@ -352,7 +355,7 @@ __declspec(dllexport) LPXLOPER WINAPI xlAutoRegister(LPXLOPER pxName)
352355
static XLOPER xDLL, xRegId;
353356
xRegId.xltype = xltypeErr;
354357
xRegId.val.err = xlerrValue;
355-
358+
356359
return (LPXLOPER) &xRegId;
357360
}
358361

@@ -402,23 +405,25 @@ __declspec(dllexport) LPXLOPER WINAPI xlAddInManagerInfo(LPXLOPER xAction)
402405
}
403406
x->val.str = addinName;
404407
return x;
405-
}
408+
}
406409

407410
return (LPXLOPER) &xInfo;
408411
}
409412

410-
LPXLOPER WINAPI FSExecute(int index, const char* name, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2, LPXLOPER v3, LPXLOPER v4,
413+
LPXLOPER WINAPI FSExecute(int index, const char* name, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2, LPXLOPER v3, LPXLOPER v4,
411414
LPXLOPER v5, LPXLOPER v6, LPXLOPER v7, LPXLOPER v8, LPXLOPER v9, LPXLOPER v10,
412415
LPXLOPER v11, LPXLOPER v12, LPXLOPER v13, LPXLOPER v14, LPXLOPER v15, LPXLOPER v16,
413-
LPXLOPER v17, LPXLOPER v18, LPXLOPER v19)
416+
LPXLOPER v17, LPXLOPER v18, LPXLOPER v19, LPXLOPER v20, LPXLOPER v21, LPXLOPER v22,
417+
LPXLOPER v23, LPXLOPER v24, LPXLOPER v25, LPXLOPER v26, LPXLOPER v27, LPXLOPER v28,
418+
LPXLOPER v29)
414419
{
415420
// Attempt connection
416421
if(!InitProtocol(index)) {
417422
return g_protocol[index]->getLastError();
418423
}
419424

420425
// Exec function
421-
LPXLOPER xres = g_protocol[index]->execute(name, g_sendCallerInfo, 20, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);
426+
LPXLOPER xres = g_protocol[index]->execute(name, g_sendCallerInfo, MAX_ARGUMENTS, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29);
422427

423428
// Check for error
424429
if(!g_protocol[index]->isConnected()) {
@@ -431,7 +436,7 @@ LPXLOPER WINAPI FSExecute(int index, const char* name, LPXLOPER v0, LPXLOPER v1,
431436

432437
// Log function call
433438
if(g_debugLogging) {
434-
XLUtil::LogFunctionCall(g_serverSections[index], name, xres, 20, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);
439+
XLUtil::LogFunctionCall(g_serverSections[index], name, xres, MAX_ARGUMENTS, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29);
435440
}
436441

437442
return xres;
@@ -441,10 +446,11 @@ LPXLOPER WINAPI FSExecute(int index, const char* name, LPXLOPER v0, LPXLOPER v1,
441446
__declspec(dllexport) LPXLOPER WINAPI FSExecute##number (const char* name, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2 \
442447
,LPXLOPER v3, LPXLOPER v4, LPXLOPER v5, LPXLOPER v6, LPXLOPER v7, LPXLOPER v8 \
443448
,LPXLOPER v9, LPXLOPER v10, LPXLOPER v11, LPXLOPER v12, LPXLOPER v13, LPXLOPER v14, LPXLOPER v15, LPXLOPER v16 \
444-
,LPXLOPER v17, LPXLOPER v18, LPXLOPER v19) \
449+
,LPXLOPER v17, LPXLOPER v18, LPXLOPER v19, LPXLOPER v20, LPXLOPER v21, LPXLOPER v22, LPXLOPER v23, LPXLOPER v24 \
450+
,LPXLOPER v25, LPXLOPER v26, LPXLOPER v27, LPXLOPER v28, LPXLOPER v29) \
445451
{ \
446-
return FSExecute(number, name, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19); \
447-
}
452+
return FSExecute(number, name, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29); \
453+
}
448454

449455
DECLARE_GENERAL_FUNCTION(0)
450456
DECLARE_GENERAL_FUNCTION(1)
@@ -467,23 +473,26 @@ DECLARE_GENERAL_FUNCTION(17)
467473
DECLARE_GENERAL_FUNCTION(18)
468474
DECLARE_GENERAL_FUNCTION(19)
469475

470-
__declspec(dllexport) LPXLOPER WINAPI FSExecuteVolatile(int index, const char* name, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2, LPXLOPER v3, LPXLOPER v4,
476+
__declspec(dllexport) LPXLOPER WINAPI FSExecuteVolatile(int index, const char* name, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2, LPXLOPER v3, LPXLOPER v4,
471477
LPXLOPER v5, LPXLOPER v6, LPXLOPER v7, LPXLOPER v8, LPXLOPER v9, LPXLOPER v10,
472478
LPXLOPER v11, LPXLOPER v12, LPXLOPER v13, LPXLOPER v14, LPXLOPER v15, LPXLOPER v16,
473-
LPXLOPER v17, LPXLOPER v18, LPXLOPER v19)
479+
LPXLOPER v17, LPXLOPER v18, LPXLOPER v19, LPXLOPER v20, LPXLOPER v21, LPXLOPER v22,
480+
LPXLOPER v23, LPXLOPER v24, LPXLOPER v25, LPXLOPER v26, LPXLOPER v27, LPXLOPER v28,
481+
LPXLOPER v29)
474482
{
475483
// Just call off to main function (as this should have the same behaviour only volatile)
476-
return FSExecute(index, name, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);
484+
return FSExecute(index, name, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29);
477485
}
478486

479487
#define DECLARE_VOLATILE_FUNCTION(number) \
480488
__declspec(dllexport) LPXLOPER WINAPI FSExecuteVolatile##number (const char* name, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2 \
481489
,LPXLOPER v3, LPXLOPER v4, LPXLOPER v5, LPXLOPER v6, LPXLOPER v7, LPXLOPER v8 \
482490
,LPXLOPER v9, LPXLOPER v10, LPXLOPER v11, LPXLOPER v12, LPXLOPER v13, LPXLOPER v14, LPXLOPER v15, LPXLOPER v16 \
483-
,LPXLOPER v17, LPXLOPER v18, LPXLOPER v19) \
491+
,LPXLOPER v17, LPXLOPER v18, LPXLOPER v19, LPXLOPER v20, LPXLOPER v21, LPXLOPER v22, LPXLOPER v23, LPXLOPER v24 \
492+
,LPXLOPER v25, LPXLOPER v26, LPXLOPER v27, LPXLOPER v28, LPXLOPER v29) \
484493
{ \
485-
return FSExecuteVolatile(number, name, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19); \
486-
}
494+
return FSExecuteVolatile(number, name, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29); \
495+
}
487496

488497
DECLARE_VOLATILE_FUNCTION(0)
489498
DECLARE_VOLATILE_FUNCTION(1)
@@ -506,24 +515,27 @@ DECLARE_VOLATILE_FUNCTION(17)
506515
DECLARE_VOLATILE_FUNCTION(18)
507516
DECLARE_VOLATILE_FUNCTION(19)
508517

509-
LPXLOPER WINAPI FSExecuteNumber(int number, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2, LPXLOPER v3, LPXLOPER v4,
518+
LPXLOPER WINAPI FSExecuteNumber(int number, LPXLOPER v0, LPXLOPER v1, LPXLOPER v2, LPXLOPER v3, LPXLOPER v4,
510519
LPXLOPER v5, LPXLOPER v6, LPXLOPER v7, LPXLOPER v8, LPXLOPER v9, LPXLOPER v10,
511520
LPXLOPER v11, LPXLOPER v12, LPXLOPER v13, LPXLOPER v14, LPXLOPER v15, LPXLOPER v16,
512-
LPXLOPER v17, LPXLOPER v18, LPXLOPER v19)
521+
LPXLOPER v17, LPXLOPER v18, LPXLOPER v19, LPXLOPER v20, LPXLOPER v21, LPXLOPER v22,
522+
LPXLOPER v23, LPXLOPER v24, LPXLOPER v25, LPXLOPER v26, LPXLOPER v27, LPXLOPER v28,
523+
LPXLOPER v29)
513524
{
514525
if(g_functionCount < number) {
515526
return &g_errorMessage;
516527
}
517-
return FSExecute(g_functionServer[number], g_functionNames[number], v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);
528+
return FSExecute(g_functionServer[number], g_functionNames[number], v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29);
518529
}
519530

520531
#define DECLARE_EXCEL_FUNCTION(number) \
521532
__declspec(dllexport) LPXLOPER WINAPI FS##number (LPXLOPER v0, LPXLOPER v1, LPXLOPER v2 \
522533
,LPXLOPER v3, LPXLOPER v4, LPXLOPER v5, LPXLOPER v6, LPXLOPER v7, LPXLOPER v8 \
523534
,LPXLOPER v9, LPXLOPER v10, LPXLOPER v11, LPXLOPER v12, LPXLOPER v13, LPXLOPER v14, LPXLOPER v15, LPXLOPER v16 \
524-
,LPXLOPER v17, LPXLOPER v18, LPXLOPER v19) \
535+
,LPXLOPER v17, LPXLOPER v18, LPXLOPER v19, LPXLOPER v20, LPXLOPER v21, LPXLOPER v22, LPXLOPER v23, LPXLOPER v24 \
536+
,LPXLOPER v25, LPXLOPER v26, LPXLOPER v27, LPXLOPER v28, LPXLOPER v29) \
525537
{ \
526-
return FSExecuteNumber(number, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19); \
538+
return FSExecuteNumber(number, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29); \
527539
}
528540

529541
DECLARE_EXCEL_FUNCTION(0)

0 commit comments

Comments
 (0)