How to use ShellExecute( )?

Trying to open Notepad.exe through its programme
ShellExecute(NULL, "open", "notepad.exe", NULL, NULL, SW_SHOWNORMAL);

The problem is that when compiled gives the error:
1. Argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
2. Argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
Don't know what it is.
September 19th 19 at 12:18
2 answers
September 19th 19 at 12:20
Solution
You are compiling with Unicode and strings in ANSI asked, here it and "ale":
ShellExecute(NULL,L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL);
How to fix? - Norene.Barrows commented on September 19th 19 at 12:23
: I have already written a fix - let's see, I finished the L at the beginning of the string constants to quotes. - Erling_Hansen79 commented on September 19th 19 at 12:26
: Thanks! - Norene.Barrows commented on September 19th 19 at 12:29
September 19th 19 at 12:22
Solution
Explain :-)
Like many WinAPI functions, from ShellExecute, you have two options: ShellExecuteA and ShellExecuteW. When you write ShellExecute, the preprocessor based on the project settings substitutes A - and W-name. A and W versions differ in the type of lines: A - ASCII W - WCHAR. Given your code uses ASCII strings, and by default, Studio includes Unicode support, then there will be the W-function and the argument types don't match.

Solutions: set the settings of the project in terms of the encoding to "undefined". To explicitly use ShellExecuteA. To pass a WCHAR string by specifying a magic simola L, for example L"open" in this case.

And Yes, C++ has nothing to do with it ;-)

Find more questions by tags Visual StudioC++