Dialogue box show via a function

Jan 15, 2013 at 2:37 AM

What am i doing wrong here ?? 

I am using excel 2007 and the session just crashes If I try to create a dialogue box. 

If possible please provide the sample code for creating dialogue box 

#include "header.h"

#include "xll\dialog.h"

#include"xll\XlCall.h"

using namespace xll;

// create function holders for Login Connection and Publishstatic AddIn

login_function( FunctionX(XLL_LPOPERX, _T("?rtr_login"), _T("RTR_LOGIN"))

.Arg(XLL_CSTRINGX, _T("str"), _T("UserName"))

.Arg(XLL_CSTRINGX, _T("str"), _T("PassWord"))

.FunctionHelp(_T("Provide login facility to the UVA System")) .Documentation(_T("Login")) );

 LPOPERX WINAPI // <- Must declare all Excel C functions as WINAPI

rtr_login(const char* LoginStr, const char* Password)

{ #pragma XLLEXPORT

static OPERX xResult;

xll::Dialog loginD("login tester",5,4,5,6);

loginD.Add(5,"to be tested",2,3,2,3); 

loginD.Show(); 

xResult.append("You have provided ").append(LoginStr).append("and").append(Password);  return &xResult; }

Coordinator
Jan 16, 2013 at 2:00 PM

The dimensions of the dialog box are kind of small. See xll\error.cpp for an example. Try xll::Dialog loginD("login tester", 5, 4, 200, 100); Sorry, not much documentation for dialog boxes. You are the only person I know that has been able to figure out this facility exists.

Windows has a credential manager you can use to whip up something that looks professional. See test\cred.cpp for an example of how to use it.

Jan 16, 2013 at 2:23 PM

Thanks a lot for pointing me towards the right direction. I am trying to use it in my work. We have a similar library in house. Once I am finished with writing the code I will surely contribute towards providing an example project. 

Thanks again !! 

Jan 17, 2013 at 7:12 AM

Hi Keith, 

It did not work properly, still keeps on crashing. 

I have to write the login box so that the username and password could be collected and set over http.. It might not be same as the credentials stored in windows. 

If you have time could you please write a small function that opens a dialog box when called from excel. That would be really helpful. 

Coordinator
Jan 17, 2013 at 10:29 AM

Hi tanmaydatta,

I need my car washed. If you have time could you please come by and wash it. Be sure to clean the windows well so I can see things clearly.

You have a working example of a dialog in xll\error.cpp. There is also a working example of using the credential manager in test\cred.cpp. Getting data over http is orthogonal to this. I'm sure you are bright enough to figure that last bit out.

You also need to read up on the credential manager. It can store anything you want.

Feb 13, 2014 at 11:54 AM
Edited Feb 13, 2014 at 12:38 PM
This discussion has been closed a year ago. Neverheless, I believe this addition can help others.

2 main sources for exploring Dialogs are:
  • Page 355 of Dalton's second book describe the mechanics (actually there is a spreadsheet in the CD-ROM, under Chapter 9, called XLM_ThreadCfg_Dialog.xls that shows the trick).
  • And, as Keith says, the Rosetta Stone, that is the Microsoft Excel Macro Functions Help. Look for DIALOG.BOX.
In fact, I needed to wash my car as well and have a simple "Input Box", so this is how it works in a very simple example:
static AddInX xai_InputBox( 
    // C function name, Excel macro name
    _T("?xll_InputBox"), _T("InputBox")
    );
int WINAPI
    xll_InputBox(void)
    {
#pragma XLLEXPORT   
        {
        OPERX Result;
        Result=ExcelX(xlfInput,OPERX(_T("Enter the inflation rate:")), NumX(3) , OPERX(_T("Inflation Rate"))); // Shows input box
        ExcelX(xlcMessage, OPERX(true), Result);    // Shows the result in the status bar
        return 1;
        }       
    }       
Coordinator
Feb 13, 2014 at 12:23 PM
Thanks OttoW. It turns out that dialog boxes are not supported in 64-bit Excel so using xlfInput if you can is preferable.