Closed TheMichalcinOfficial closed 2 years ago
OPERs are passed in as pointers
xll::OPER WINAPI xll_myfunc(xll::LPOPER timestamps)
{
#pragma XLLEXPORT
return timestamps->size();
}
It's still getting assigned to nullptr.
I missed that you are returning a long:
xll::AddIn xai_myfunc(
xll::Function(XLL_LONG, "xll_myfunc", "MYFUNC")
.Arguments({ xll::Arg(XLL_LPOPER, "timestamps", "range of cells containing timecodes") })
.FunctionHelp("Test function")
);
LONG WINAPI xll_myfunc(xll::LPOPER timestamps)
{
#pragma XLLEXPORT
return timestamps->size();
}
Oh yeah, that fixed it. So I just got lost with my types... One last question: can I somehow modify the multi, or return a new multi as a result? I'd like to write a function, that takes in a range of cells and then fills another range of cells with values.
You might find this identity function on a cell (or range of cells) helpful. Just replace o = *po
as required, and extend xll_func
's signature to include other cells, if needed.
xll::LPOPER WINAPI xll_func(xll::LPOPER po) {
#pragma XLLEXPORT
static xll::OPER o;
try {
// do something more interesting
o = *po;
}
catch (std::exception& e) {
o = e.what();
}
return &o;
}
AddIn xai_func(
Function(XLL_LPOPER, "xll_func", "XLL.FUNC")
.Arguments({
Arg(XLL_LPOPER, "po", "cells")
})
);
Thanks @rmcrkd!
Thanks, all of you! :-)
Hello, I am currently trying to learn how to use this library and I am facing some issues. I need to write a function that takes in a range of excel cells, reads them and then returns some integer output based on what was in those cells. Since I am just learning, I wanted to return the size of the range. Here is my code:
When I try to call the function in excel and hit Enter, the process (running in debug mode) crashes and throws an exception saying that the OPER was set to nullptr. The program crashes inside the
xll::type()
function. I fear that I'm making a dumb mistake, but I can't figure it out...