Problem when calling XLL from another XLL

Dec 29, 2013 at 3:01 AM
I am calling the function in XLL-A from another XLL, named XLL-B, using LoadLibrary and GetProcAddress function. However, when I use depends.exe to find what functions I have in the XLL-A, I can not find the correct one. For example, the XLL-A is a "plus4" function and I can type in "=plus4(x,y)" in Excel cell. But I can not see plus4 or plus4_Impl in depends.exe, I can only see plus4_12 and plus4_4. Neither can I call plus4 or plus4_Impl in the XLL-B. But with plus4_12 and plus4_4, I can not get the correct answer because they are not the right function.

My code for XLL-A: 3 functions, plus4_4, plus4_12, plus_Impl

IMPLEMENT_XLLFN4(plus4, plus4_4, plus4_12, "RBB", "UBB$", L"plus4", 0, L"x,y",
0, L"14", 0, L"", 0, L"\0\0", 0, 0, L"{plus4,,,{},14,1,1,U,{{0,{x,Double,0"
L",,,,,,}},{0,{y,Double,0,,,,,,}}},{},3,,0,0,,,,0,0}", 1, 0, 0)
CXlOper* plus4_Impl(CXlOper&, double, double);
extern "C" __declspec(dllexport)
LPXLOPER12 plus4_12(double x, double y)
{
XLL_FIX_STATE;
CXlOper xloResult;
try {
    CXlStructuredExceptionHandler _seh_;
    xloResult.HandleResult(plus4_Impl(xloResult, x, y));
}
catch(const CXlRuntimeException& ex) {
    CXllApp::Instance()->DisplayException(xloResult, ex);
}
XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 plus4_4(double x, double y)
{
XLL_FIX_STATE;
CXlOper xloResult;
try {
    CXlStructuredExceptionHandler _seh_;
    xloResult.HandleResult(plus4_Impl(xloResult, x, y));
}
catch(const CXlRuntimeException& ex) {
    CXllApp::Instance()->DisplayException(xloResult, ex);
}
XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
return xloResult.Ret4();
}

CXlOper* plus4_Impl(CXlOper& xloResult, double x, double y)
{
// End of generated code
//}}XLP_SRC
// TODO - set the value of xloResult, or return another value
//        using CXlOper::RetXXX() or throw a CXlRuntimeException.
xloResult=x+y;
return xloResult.Ret();
}

Code for XLL-B:

CXlOper* plus4_xlltest_5_Impl(CXlOper& xloResult, double x, double y)
{
// End of generated code
//}}XLP_SRC
// TODO - set the value of xloResult, or return another value
//        using CXlOper::RetXXX() or throw a CXlRuntimeException.
xloResult=main2(x,y);
return xloResult.Ret();
}

double main2(double x, double y)
{
using namespace std;
double c;
typedef double (FUNA)(double,double*);
HINSTANCE hDLL;
FUNA funa;
hDLL = LoadLibrary(TEXT("dec_22_3.xll"));//
     funa = (FUNA)GetProcAddress(hDLL,"plus4_12"); 
            if(funa != NULL)
            {
             c=(*funa)(&x,&y);
             return c;
            }
            else
            {
             return 0;
            }
          FreeLibrary(hDLL);
}
Coordinator
Dec 29, 2013 at 3:28 AM
Thanks for posting this here so other people can benefit from the issues you are dealing with.

Plus4_Impl is not being exported.

The great thing about computers is that they do exactly what you tell them to do.
The awful thing about computers is that they do exactly what you tell them to do.

XllPlus is old technology. C++ has moved past that. Get hooked up with the new stuff the smartest people in the community are doing.
http://isocpp.org/blog/2013/12/a-shared-view is a good start. Bjarne knows a thing or two about C++ and is focused on how to teach people about the latest advances.

Hua dao lao, xue dao lao, hai you san fen sui bu dao.