I want to make a reusable function that I can reuse whenever I want to use a MessageBox but in the code below, there is an error saying:
identifier "Lmessage" is undefined
identifier "Ltitle" is undefined
'Lmessage': undeclared identifier
'Ltitle': undeclared identifier
#include <iostream>
#include <string>
#include <Windows.h>
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
int takePrompt(int number, std::string message, std::string title) {
return MessageBox(0, TEXT(message), TEXT(title), MB_YESNO);
}
int main() {
if (takePrompt(0, "", "1") == IDYES) {
MessageBox(0, TEXT(""), TEXT("1.1"), MB_ICONEXCLAMATION);
} else {
if (takePrompt(0, "", "2") == IDYES) {
MessageBox(0, TEXT(""), TEXT("2"), MB_ICONEXCLAMATION);
} else {
while (takePrompt(0, "", "3") != IDNO) {
if (takePrompt(0, "", "4") == IDYES) {
MessageBox(0, TEXT(""), TEXT("4.2"), MB_ICONEXCLAMATION);
} else {
return 1;
}
}
}
}
return 0;
}
I tried putting std::string title, message, but it did not solve the problem. I just want a reusable MessageBox that I can change and give value whenever I want to
TEXTis for string literals, not for variables. And Windows API being related to C is not familiar with C++std::string. You can usestd::string::c_str()to get a null terminated C string from thestd::string, but if will work only for an ascii build, not a unicode one (or you can explicitly useMessageBoxA). You can make yourtakePromptfunction accept parameters as expected by the Windows API, i.e.LPCTSTRfor the strings.