Domanda

I am new to C++ (I came from PHP) and during my first few projects I am experiencing quite some errors from IntelliSense. What debug window say is:

IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR" c:\C++\RenderEngine\RenderEngine\engine.c

This error even appear when I run that simple code:

#include <Windows.h>

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
    MessageBox(NULL, "Hello, world!", "Simple pop-up", MB_OK);
    return 0;
}

However, if I put "L" before quotes ( L"Hello, world!" ) error dissappear. Is it possible to get rid of it any different way? (The tutorial which I was following did not had the L infront, so it is VERY confusing for me ...) I have been looking over the internet, but I haven't found anything useful ... Sorry if a question like this have been already answered and only I haven't seen it ...

Sincerely, Armin Makovec.

È stato utile?

Soluzione

The error is because you're using 8 bit char strings in a place that expects wide char strings. A string constant in quotes is an ASCII (8 bit) string, putting L before it, such as L"A string constant" means it is a wchar_t string.

Solving it as you did, by setting the environment properties to always use wchar_t strings is one way to solve it, but it won't compile anywhere else if you do this. It's generally better to do it the portable way and just use wchar_t strings by starting a string literal with L.

Altri suggerimenti

Managed to solve it by going to: "Project->(Project name) Properties->Configuration Properties->General->Character Set" and setting it to Multi-byte Character set

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top