in_function_wizard() gives error

Nov 28, 2012 at 12:19 AM

Hi Keith,

following your suggestion i am using 

inline bool in_function_wizard(void)

{
       return !ExcelX(xlfGetTool, OPERX(4), OPERX(_T("Standard")), OPERX(1));
}

to check if i am within function wizard.

but if the return of my c function is a lpoperx and i do something like:

LPOPERX WINAPI 

cfunc(void)

{

#pragma XLLEXPORT

 static OPERX result(0);

 if(in_function_wiziard())

 return &result;

/* rest of the code below */ 

}

then i get errror thrown :

 

xlretInvXlfn: throw std::runtime_error("Excel returned invalid function number").

 

it would be very kind of you to make some comment regarding this.

 

Best


Coordinator
Nov 28, 2012 at 2:08 AM

If you send me code I can compile and run on my computer, I'll try to help you. Have a closer look at what you sent me.

static OPERX result(0);

if(in_function_wiziard())

return &result;

Nov 28, 2012 at 2:54 PM

Hi Keith,

thanks for your comments: let me give you two example (one works and one doesn't)

------------------------------------------------this one works----------------------------

static

AddInX xai_return_double(Function12(XLL_DOUBLEX, _T("?xll_return_double"), _T("test.double" )) .Arg(XLL_LPOPERX, _T("Dummy"), _T("dummy arg" )));

 double WINAPI xll_return_double(LPOPERX dummy)

{

 

#pragma

XLLEXPORT  

 double

output(0.);
 

 

 try

{ if (in_function_wizard()) return output; } 

 

 catch (const

std::exception& ex) {std::wstring err_mesg=strings::mbstowcs(ex.what());}

 return

output;

};

 

 

-----------------this doesn't, throws exception----------------------

 

static

AddInX xai_return_oper(Function12(XLL_LPOPERX, _T("?xll_return_oper"), _T("test.oper" )) .Arg(XLL_LPOPERX, _T("Dummy"), _T("dummy arg")));
 

LPOPERX WINAPI xll_return_oper(LPOPERX dummy)

{

#pragma

XLLEXPORT  

 

static OPERX output = NumX(0);
 

 

try {if(in_function_wizard()) return &output; } 

 catch (const

std::exception& ex) {std::wstring err_mesg=strings::mbstowcs(ex.what());output = OPERX(err_mesg.c_str());}&output;

 return

};

 

inline bool in_function_wizard(void)

{
       return !ExcelX(xlfGetTool, OPERX(4), OPERX(_T("Standard")), OPERX(1));
}

Coordinator
Nov 28, 2012 at 4:52 PM
catch (const std::exception& ex) {
    std::wstring err_mesg=strings::mbstowcs(ex.what());
    output = OPERX(err_mesg.c_str());
}

&output;  return 

should be return &output;
Also, don't mix and match X and 12 suffixes. 
Nov 28, 2012 at 4:57 PM

sorry in the code i have it as return &output; while copying and pasing i missed it.

that is not what causes the problem. the exception is thrown from in_function_wizard()

Coordinator
Nov 29, 2012 at 3:04 AM

I was not able to repoduce this in Excel 2003, but you are correct about Excel 2010. I have not tested this in Excel 2007.

People have been asking for this. The Microsoft SDK has a solution. My position is that if your code is so slow that you need to figure out if you are in the function wizard, then your code is too slow.

If you look at the Related Projects sidebar you might find some more interesting things you can contribute to.