Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have the following piece of code inside a function and I need to shows a user's error message. But the message is not shown. Only the return's value... What did I do wrong ?

Regards.

C++
const double dia = 1.0;

 xloper xStr, xInt;

 xStr.xltype = xltypeStr;
 xStr.val.str = new_xlstring("User's message.");
 xInt.xltype = xltypeInt;
 xInt.val.w = 2; 


if(terNum < segNum)
{
    Excel4(xlcAlert, NULL, 2, &xStr, &xInt);
    return 0.0;
}

free(xStr.val.str);
Posted
Updated 21-Oct-14 13:32pm
v2

1 solution

I have never managed to get xlcAlert to work in functions. So, I use MessageBoxW. Here is an example, using your code as a starting point, which works:

C++
__declspec(dllexport) LPXLOPER12 XLLShowMessageA (void)
{
    static XLOPER12 xReturn;
    int             terNum, segNum, rc;


    terNum = 1;
    segNum = 2;
	
    xReturn.xltype = xltypeNum;
    xReturn.val.num = 0;  

    if (terNum < segNum)
    {
        MessageBoxW (NULL, L"User message.", L"Dialog title.", 
                     MB_OK | MB_SETFOREGROUND );		
        return &xReturn;
    }
  
    return &xReturn;
}

David Wilkinson (UK)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900