passing default arguments

Sep 21, 2012 at 9:50 PM

hi Keith,

may i seek your help with the following issue:

i am tring to pass default arguments how do it do it.

for instance i have the following code

static AddInX xai_create_xll(
Function12(XLL_HANDLEX, L"?xll_create_xll", L"qv.create")
 .Arg(XLL_DOUBLEX, L"a1",L"arg1")
 .Arg(XLL_LPOPERX, L"a2",L"arg2")
 .Arg(XLL_LPOPERX, L"a3", L"arg3")
 .Arg(XLL_LPOPERX, L"a4", L"arg4")
 .Arg(XLL_DOUBLEX, L"a5",L"arg5 default")
  .Uncalced()
 .Category(L"Example")
 .FunctionHelp(L"creates model")
);

HANDLEX WINAPI
xll_create_xll(
					 double  a1	
					,LPOPERX a2
					,LPOPERX a3
					,LPOPERX a4
					,double  a5=0.1

				  ){

// other codes here.
}
i want the 5th argument to be defaulted to 0.1. But when i call the function like above
what heppens is the 5th argument is take in as 0. instead of the default value i am supplying. is there a 
way i can tell the code that some arguments are defaults.
Best
Coordinator
Sep 22, 2012 at 3:02 AM

If it makes you feel any better, I have trouble too when it comes to getting codeplex posts to show up how I would like them to appear after posting a code example. For simple things I fall back to html source.

You cannot use C++ defaults for Excel. As you observed, Excel will pass you 0 or OPER's of xltypeMissing. You have to check for that and manually assign the values you want.

Pro tip: You can use AddIn, OPER, and "string" or use AddIn12, OPER12, and L"string" if you want to target pre 2007 and post 2007. If you want to write one set of source code to target both based on defining the EXCEL12 macro, use AddInX, OPERX, and _T("string").