I have a program I've been working on and revising for quite some time, and I keep trying to cut down on repetitive stuff. I'm trying to come up with an easier way to show errors while including variables. I need to show info about the input that caused the error. I don't like having to declare a char array, sprintf, and MessageBox everywhere. I want a 1 line solution like a ShowError function that I basically send printf formatted input to. Problem being, can I turn around and pass the whole argument list to sprintf somehow? I've used the va_list stuff before for other things, but I don't know how I'd go about passing the whole list at once or if it's even possible. I'd probably never be passing more than 4 or 5 vars, so maybe I could make the function go through processing everything separately if I had to. I thought I'd see if anyone here had a better idea though.
Code:
ShowError("Address %x is too high. Area specified must be between %x and %x.", Var1, Var2, Var3);
int ShowError(const char* FmtString, ...)
{
char tmpText[4096];
sprintf(tmpText, FmtString, ...);
MessageBox(NULL, tmpText, "Error", MB_OK);
}