Alternative for ON_COMMAND message map macro to call a function with a paramenter(s)

198 views Asked by At

I've got a message map at the beginning of my program that looks like the following:

BEGIN_MESSAGE_MAP(SoftwareDlg, CDialog)
    //{{AFX_MSG_MAP(SoftwareDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_TIMER()
    ON_WM_DESTROY()
    ...
    ON_COMMAND(ID_TOOLS_UPLOADDATA, UploadData)
    ...
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

And here the function that the ID_TOOLS_UPLOADDATA menu option calls when clicked:

void UploadData()
{
    string apiEndpoint = "/api/stuff";
    upload_data(apiEndpoint);
}

My problem is that that I want my UploadData() function to be able to take the string apiEndpoint as a parameter so that I can call it from multiple locations in my program for multiple operations (not just when the user clicks the menu button). Like so:

void UploadData(string apiEndpoint = "/api/stuff")
{
    upload_data(apiEndpoint);
}

I took a look at ON_COMMAND_EX, but the only usage example I was able to find does not appear to be what I'm looking for... Anyone have any ideas?

1

There are 1 answers

1
Aganju On BEST ANSWER

As @Iinspectable said, you can’t.
Try for example to add a member variable and set it before calling the function.