1

I have a very big problem... I' ve started today morning programming in Windows.h but I can't figure out why it gave me this problem as I litteraly copy the thing in the tut. (https://youtu.be/8GCvZs55mEM?t=5m20s) (I put the link to start the video when occurs my error)

The only thing I noticed is that in the tut it uses a LPCSTR variable for test, but my editor (Visual Studio Code) signal a LPCWSTR variable.

Sorry for the bad English.

#include <windows.h>

using namespace std;

int WINAPI WinMain (HINSTANCE hInts, HINSTANCE hPrevInst, LPSTR args, int ncmdshow)
{

MessageBox(NULL, "Ciao!", "La prima GUI", MB_OK, );

return 0;
}

How can I solve?

In the comment:

Now the error don't show up, thanks a lot. But there is a problem... The editor don' t built the application. The Console give:

Executing task: g++ -g main.cpp -o Program <  
main.cpp: In function 'int WinMain(void *, void *, char *, int)':
main.coo:8: pasing '__wchar_t *' as argument 2 of 'MessageBox(void *, const char *, const char *, UINT)'
  • Possible duplicate of [Convert char\[\] to LPCWSTR](https://stackoverflow.com/questions/3225682/convert-char-to-lpcwstr) – Barmar Feb 09 '18 at 21:05
  • 1
    The qick fix is to use wide string literals. Just put L infront if the strings. Like L"Ciao!" – Mihayl Feb 09 '18 at 21:06
  • Welcome to Stack Overflow, please review: https://stackoverflow.com/help/how-to-ask – Daniel Feb 09 '18 at 21:07
  • If you watch carefully, you can see that `MessageBox` is just a macro and on the video it is referred to `MessageBoxA` which is ANSI variant and will take `const char *` – Killzone Kid Feb 09 '18 at 21:41

1 Answers1

4

Obviously not a good tutorial. Do it like like this

MessageBox(NULL, L"Ciao!", L"La prima GUI", MB_OK);

Using L changes the string literal so that it uses wide characters. A wide character string literal can be converted to the type LPCWSTR, a normal string literal cannot.

john
  • 85,011
  • 4
  • 57
  • 81
  • Now the error don't show up, thanks a lot. But there is a problem... The editor don' t built the application. The Console give: Executing task: g++ -g main.cpp -o Program < (new line, I can' t do it in the comment lol..) main.cpp: In function 'int WinMain(void *, void *, char *, int)': (new line) main.coo:8: pasing '__wchar_t *' as argument 2 of 'MessageBox(void *, const char *, const char *, UINT)' – Tommaso Giubilei Feb 09 '18 at 21:19
  • @TommasoGiubilei, VS defines `UNICODE` by default. You should also define it when compiling. – chris Feb 09 '18 at 21:20
  • it' s activated, in the file c_cpp_proprierties.json under the configuration Win32 there is: "defines": [ "_DEBUG", "UNICODE" ], – Tommaso Giubilei Feb 09 '18 at 21:28