type const char * not compatible with LPCWSTR

Hello everyone, Trying Win API 32 with creating sample Window, handle message using ressources in CPP compiler returns the message const char * type argument not compatible with LPCWSTR (aka const WCHAR) my code:
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName, <== here error msg is!
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
Windows 11 x64!
I'm a bleubyte also sorry for disturb you!
Really thanks
Trouthie
Last edited on
If you're compiling as Unicode then win32 APIs expect unicode text strings. If you want to use the ASCII versions then you need to explicitly use the ASCII versions. For the above, try

CreateWindowExA(...)

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexa

The specific wide-char version is CreateWindowExW(...)

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw


If neither W nor A is specified then the version used depends upon whether UNICODE is defined or not.
Please learn to use code tags to make your code easier to read.

https://www.cplusplus.com/articles/jEywvCM9/

Hint, you can edit your post and add them.

M'ok, you are using a WinAPI function that is actually a macro for two different functions. Depending on if you are compiling with Unicode or ANSI.

What is your compiler? Depending on the compiler it could default to Unicode, so having an ANSI string is gonna fail. I do know that Windows XP and later use Unicode exclusively. Win9X/Me used ANSI functions/structs/strings.

I'd opine you are using Visual Studio based on the error. 2022?

There are two simple and different ways to solve the issue.

1. You are using an ANSI string for the window title. Wrap your string in the TEXT() macro.

https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-text

2. Explicitly declare ALL of the WinAPI functions/structs/strings that have ANSI/Unicode versions as one or the other. As seeplus suggests.

I personally would recommend using the W (Unicode) versions instead of the A (ANSI) versions with your OS. Then all WinAPI strings are preceded by an L to inform the compiler this is a Unicode string. L"some text".

There are other changes I'd make to the code, such as using wWinMain, the Unicode version instead of the ANSI WinMain.

There's a decent online tutorial for the very basics of WinAPI programming, theForger's Win32 API Programming Tutorial

http://www.winprog.org/tutorial/

I've revised the code bare minimums to be modern Windows compliant:

https://github.com/GeorgePimpleton/theForger-winapi-tutorial
Scite (may be you know it) & G++ compiler seems to be running using code from winprog.org/tutorial next step is dialog boxes and ressources... V.S. Code returns the fatal error using Clang then i have to understand and know your revised version you sent me better. I have been using Visual Studio 2022 too but not in this case for years, 2 or 3 C# projects using MySql database, .net...; Python on VS Code and many others very interesting languages they come to us. This forum appears to me very serious, members as well! Saas is very interesting and conceptual, Cryptography or keygen as a service looks like exciting! But my brain is too small to pratice code programming on Windows, Linux and Mac Os! Regards. Thierry
M'ok, looking closer at your code snippet, using code tags it would have been easier to read, it looks to be code from theForger's tutorial.
1
2
3
4
5
6
7
8
	// Step 2: Creating the Window
	hwnd = CreateWindowEx(
		WS_EX_CLIENTEDGE,
		g_szClassName,
		"The title of my window",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
		NULL, NULL, hInstance, NULL);

Posting a complete compilable code snippet is a better way to show where the error(s) actually come from. (Using code tags also puts up line numbers so pointing out where errors are is easier.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CLOSE:
			DestroyWindow(hwnd);
		break;
		case WM_DESTROY:
			PostQuitMessage(0);
		break;
		default:
			return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;

	//Step 1: Registering the Window Class
	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.style		 = 0;
	wc.lpfnWndProc	 = WndProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = g_szClassName;
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, "Window Registration Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	// Step 2: Creating the Window
	hwnd = CreateWindowEx(
		WS_EX_CLIENTEDGE,
		g_szClassName,
		"The title of my window",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
		NULL, NULL, hInstance, NULL);

	if(hwnd == NULL)
	{
		MessageBox(NULL, "Window Creation Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	// Step 3: The Message Loop
	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}

The error isn't at line 53, it actually happens at line 3 where you define your global string. Line 53 errors out because your compiler tries to compile CreateWindowEx as a Unicode function. It expects the window name parameter to be a Unicode string, not ANSI.

The code has several errors that are related to using ANSI strings when compiling as Unicode.

A revision for modern Windows could be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <windows.h>

PCWSTR g_className = L"myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch ( msg )
   {
   case WM_CLOSE:
      DestroyWindow(wnd);
      break;

   case WM_DESTROY:
      PostQuitMessage(0);
      break;

   default:
      return DefWindowProcW(wnd, msg, wParam, lParam);
   }

   return 0;
}

// Step 0: Windows desktop WinAPI app entry point
int WINAPI wWinMain(_In_     HINSTANCE inst,
                    _In_opt_ HINSTANCE prevInst,
                    _In_     PWSTR     cmdLine,
                    _In_     int       cmdShow)
{
   UNREFERENCED_PARAMETER(prevInst);
   UNREFERENCED_PARAMETER(cmdLine);

   WNDCLASSEXW wc = { 0 };
   HWND        wnd;
   MSG         msg;

   // Step 1: Registering the Window Class
   wc.cbSize        = sizeof(WNDCLASSEXW);
   wc.style         = 0;
   wc.lpfnWndProc   = WndProc;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = inst;
   wc.hIcon         = (HICON)   LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
   wc.hCursor       = (HCURSOR) LoadImageW(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
   wc.hbrBackground = (HBRUSH)  (COLOR_WINDOW + 1);
   wc.lpszMenuName  = NULL;
   wc.lpszClassName = g_className;
   wc.hIconSm       = (HICON) LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);

   if ( !RegisterClassExW(&wc) )
   {
      MessageBoxW(NULL, L"Window Registration Failed!", L"Error!",
                  MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   // Step 2: Creating (and showing) the Window
   wnd = CreateWindowExW(WS_EX_CLIENTEDGE,
                         g_className,
                         L"The title of my window",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
                         NULL, NULL, inst, NULL);

   if ( wnd == NULL )
   {
      MessageBoxW(NULL, L"Window Creation Failed!", L"Error!",
                  MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   ShowWindow(wnd, cmdShow);
   UpdateWindow(wnd);

   // Step 3: The Message Loop
   while ( GetMessageW(&msg, NULL, 0, 0) > 0 )
   {
      TranslateMessage(&msg);
      DispatchMessageW(&msg);
   }
   return (int) msg.wParam;
}

Several of the other changes, such as using SAL notation and using LoadImage vs. LoadIcon/LoadCursor aren't so obvious.

About SAL Notation:
https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170

LoadIcon/LoadCursor have been deprecated, LoadImage should be preferred in new WinAPI Desktop code.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadicona

Using a WinAPI string (PCWSTR) instead of character array is also not obvious. Learning all the various WinAPI data types is helpful.
https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types

With 64-bit Windows there are even more WinAPI data types.
https://learn.microsoft.com/en-us/windows/win32/winprog64/the-new-data-types

Looking over my revised theForger code I noticed I hadn't fully used all of the Unicode WinAPI functions, specifically CreateWindowExW. OOOOPS! I've fixed that now.
I agree but a little bit busy today I will come back as soon as possible really thanks for helping me! Regards. Thierry
You can code Windows programs so that the code doesn't need to know whether compiled as Unicode or ASCII. There is the TEXT macro that returns either a wide string or an ASCII string depending on how compiled. There is also PTSTR which either points to a unicode or ASCII text and TCHAR is either wchar_t or char as appropriate etc etc etc. Don't forget auto! Consider this which compiles/runs whether compiled as unicode or ASCII:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

#include <windows.h>

constexpr auto g_className { TEXT("myWindowClass") };

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
		case WM_CLOSE:
			DestroyWindow(wnd);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		default:
			return DefWindowProc(wnd, msg, wParam, lParam);
	}

	return 0;
}

// Step 0: Windows desktop WinAPI app entry point

#ifdef UNICODE
int WINAPI wWinMain(_In_ HINSTANCE inst, _In_opt_ HINSTANCE, _In_ LPTSTR, _In_ int cmdShow) {
#else
int WINAPI WinMain(_In_ HINSTANCE inst, _In_opt_ HINSTANCE, _In_ LPTSTR, _In_ int cmdShow) {
#endif

	WNDCLASSEX wc { };
	HWND wnd;
	MSG msg;

	// Step 1: Registering the Window Class
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = 0;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = inst;
	wc.hIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
	wc.hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = g_className;
	wc.hIconSm = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);

	if (!RegisterClassEx(&wc)) {
		MessageBox(NULL, TEXT("Window Registration Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	// Step 2: Creating (and showing) the Window
	wnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_className, TEXT("The title of my window"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, inst, NULL);

	if (wnd == NULL) {
		MessageBox(NULL, TEXT("Window Creation Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(wnd, cmdShow);
	UpdateWindow(wnd);

	// Step 3: The Message Loop
	while (GetMessage(&msg, NULL, 0, 0) > 0) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;
}

Last edited on
Hello, I am coming back with a problem you anticipated but I c'ant solve it! Unicode seems to be accepted at the compilation stage, execution is throwing errors such like these:
1
2
C:/msys64/ucrt64/include/winuser.h:4203:63: note:   initializing argument 2 of 'void* LoadImageW(HINSTANCE, LPCWSTR, UINT, int, int, UINT)'
 4203 |   WINUSERAPI HANDLE WINAPI LoadImageW(HINSTANCE hInst,LPCWSTR name,UINT type,int cx,int cy,UINT fuLoad);;

Rememberprogramming is complicated. ;) Thierry
It would be helpful to show your LoadImageW function, without it the error by itself is not at all helpful.

BTW, that error reads more like a compilation error, not one seen during app execution.

FYI, the Win SDK your compiler is using is looking to be a source of problems. LoadImageW's return value is HANDLE, not void *.

Visual Studio can compile theForger code as is. You have to use Multi-Byte Character Set, not Unicode.

Main Menu: Project -> (project name)'s properties - > Configuration Properties -> Advanced -> Character Set.

The property likely defaults to Unicode, it does for me.

Showing us the entire code would benefit us so we can help you.
thank you very much, note that I am using V.S. Code not Visual studio do you think I have to use the visual studio 2022 ' compiler? The code is a copy/paste of your!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <windows.h>
#include <sal.h>
#include <winuser.h>
PCWSTR g_className = L"myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch ( msg )
   {
   case WM_CLOSE:
      DestroyWindow(wnd);
      break;

   case WM_DESTROY:
      PostQuitMessage(0);
      break;

   default:
      return DefWindowProcW(wnd, msg, wParam, lParam);
   }

   return 0;
}

// Step 0: Windows desktop WinAPI app entry point
int WINAPI wWinMain(_In_     HINSTANCE inst,
                    _In_opt_ HINSTANCE prevInst,
                    _In_     PWSTR     cmdLine,
                    _In_     int       cmdShow)
{
   UNREFERENCED_PARAMETER(prevInst);
   UNREFERENCED_PARAMETER(cmdLine);

   WNDCLASSEXW wc = { 0 };
   HWND        wnd;
   MSG         msg;

   // Step 1: Registering the Window Class
   wc.cbSize        = sizeof(WNDCLASSEXW);
   wc.style         = 0;
   wc.lpfnWndProc   = WndProc;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = inst;
   wc.hIcon         = (HICON)   LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
   wc.hCursor       = (HCURSOR) LoadImageW(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
   wc.hbrBackground = (HBRUSH)  (COLOR_WINDOW + 1);
   wc.lpszMenuName  = NULL;
   wc.lpszClassName = g_className;
   wc.hIconSm       = (HICON) LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);

   if ( !RegisterClassExW(&wc) )
   {
      MessageBoxW(NULL, L"Window Registration Failed!", L"Error!",
                  MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   // Step 2: Creating (and showing) the Window
   wnd = CreateWindowExW(WS_EX_CLIENTEDGE,
                         g_className,
                         L"The title of my window",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
                         NULL, NULL, inst, NULL);

   if ( wnd == NULL )
   {
      MessageBoxW(NULL, L"Window Creation Failed!", L"Error!",
                  MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   ShowWindow(wnd, cmdShow);
   UpdateWindow(wnd);

   // Step 3: The Message Loop
   while ( GetMessageW(&msg, NULL, 0, 0) > 0 )
   {
      TranslateMessage(&msg);
      DispatchMessageW(&msg);
   }
   return (int) msg.wParam;
}

Errors from VS CODE:
1
2
3
cannot convert 'LPSTR' {aka 'char*'} to 'LPCWSTR' {aka 'const wchar_t*'}
cannot convert 'LPSTR' {aka 'char*'} to 'LPCWSTR' {aka 'const wchar_t*'}
cannot convert 'LPSTR' {aka 'char*'} to 'LPCWSTR' {aka 'const wchar_t*'}

Are underligned: IDI_APPLICATION IDC_ARROW
Thierry
constexpr auto g_className { TEXT("myWindowClass") };

That variable initialization is C++ code, not C. theForger's code is entirely written using C/WinAPI. :)

My minimal rewrite of the simple_window.c example, compiled as C, using C rules and WinAPI features:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <windows.h>

const TCHAR g_szClassName[ ] = TEXT( "myWindowClass" );

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   switch ( msg )
   {
   case WM_CLOSE:
      DestroyWindow( hwnd );
      break;
   case WM_DESTROY:
      PostQuitMessage( 0 );
      break;
   default:
      return DefWindowProc( hwnd, msg, wParam, lParam );
   }
   return 0;
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR lpCmdLine, int nCmdShow )
{
   WNDCLASSEX wc;
   HWND hwnd;
   MSG Msg;

   //Step 1: Registering the Window Class
   wc.cbSize		 = sizeof( WNDCLASSEX );
   wc.style		 = 0;
   wc.lpfnWndProc	 = WndProc;
   wc.cbClsExtra	 = 0;
   wc.cbWndExtra	 = 0;
   wc.hInstance	 = hInstance;
   wc.hIcon		 = LoadIcon( NULL, IDI_APPLICATION );
   wc.hCursor		 = LoadCursor( NULL, IDC_ARROW );
   wc.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 );
   wc.lpszMenuName  = NULL;
   wc.lpszClassName = g_szClassName;
   wc.hIconSm		 = LoadIcon( NULL, IDI_APPLICATION );

   if ( !RegisterClassEx( &wc ) )
   {
      MessageBox( NULL, TEXT( "Window Registration Failed!" ), TEXT( "Error!" ),
                  MB_ICONEXCLAMATION | MB_OK );
      return 0;
   }

   // Step 2: Creating the Window
   hwnd = CreateWindowEx(
      WS_EX_CLIENTEDGE,
      g_szClassName,
      TEXT( "The title of my window" ),
      WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
      NULL, NULL, hInstance, NULL );

   if ( hwnd == NULL )
   {
      MessageBox( NULL, TEXT( "Window Creation Failed!" ) , TEXT( "Error!" ),
                  MB_ICONEXCLAMATION | MB_OK );
      return 0;
   }

   ShowWindow( hwnd, nCmdShow );
   UpdateWindow( hwnd );

   // Step 3: The Message Loop
   while ( GetMessage( &Msg, NULL, 0, 0 ) > 0 )
   {
      TranslateMessage( &Msg );
      DispatchMessage( &Msg );
   }
   return Msg.wParam;
}

There are subtle and (not so subtle) differences in how code is seen as valid code by the compiler in C vs. C++. As you know, seeplus.

It helps to remember C++ code can be structured differently than C code. Declaration of variables, for instance. Strict C requires(?) all variables be declared at the head of the function/code block where they are used. They can be defined later.

Extensions can (and do) change that.

C++ allows variable to be declared and defined near their first use. That can be somewhat confusing at first. Especially if one only knows the C rules.

The Desktop WinAPI could be viewed as a C extension. :Þ

Personally I compile most times strict C/WinAPI code as C++. Occasionally I compile as C to catch possible warnings and errors.
It perfectly runs right now! Nice! I have totally forgotten difference between C & C++ sory for disturbing you! I have to complete the project now! See you! Bye bye Thierry
TrouthieCPP wrote:
I am using V.S. Code not Visual studio do you think I have to use the visual studio 2022 ' compiler?

I have tried VS Code and found it lacking features available in Visual Studio 2022. Features I routinely use. Mostly extensions. And built-in debugging.

If you can get code to compile with VS Code there's no need to switch over. VS 2022 can be rather hefty, it installs a lot of "stuff" that VS Code doesn't. If you have the space why not install both?

VS Code is not designed to deal natively with WinAPI code, that's one reason to at least consider VS 2022.

One caveat with VS 2022, it requires a 64-bit processor. VS Code doesn't. VS Code can also be used on other OSes. There are MacOS and Linux flavors.

About your #includes....
1
2
3
#include <windows.h>
#include <sal.h>
#include <winuser.h> 

You don't need the <sal.h> or <winuser.h> headers, they should be automatically included when including <windows.h>.

I don't know what the WinAPI SDK is for VS Code, IIRC C/C++ has to be installed as a language add-on, it might be quite different than what's part of Visual Studio 2022.

For that matter C++ is a separate workload that isn't installed with the VS 2022 default setup either. It has to be either manually added when installing or added later.

There's more to developing Win apps than using the Desktop WinAPI available. Windows Platform and WinUI and .NET are just a few of the additional frameworks available.

Not that I use the features VS 2022 has optional workloads/components that can be installed to create multi-platform apps with theoretically a single codebase. GUI or C++ console/command-line interface. If VS Code has similar features I wouldn't know.

sory for disturbing you!

Your questions were not even remotely a bother and disturbance. If we didn't want to help we would have just ignored you.
C:/msys64/ucrt64
From experience MSYS/MinGW64 is not the best compiler for WinAPI. It can cause problems that don't happen when compiling with MSBuild in VS 2022. As you've seen.

Writing Desktop WinAPI apps can be frustrating enough using VS 2022 and MSBuild, using a 3rd party compiler's SDK can make things even harder.
Even if the laptop is used (i7 16Go 1To ssd) both v.s. 2019 & 2022 are installed plus V.S. Code on Windows x64 11 pro the best plan is a devlopper station in a virtual console like Virtual Box! Msys64 has to be installed in V.S. code as a part of C/C++ extension for it. Scite and Notepad are using G++ MinGw and best compiler for WinApi is the MS Visual C++ compiler may be!It becomes harder writing applications anyway with C++ and MASM but it's a good exercice! WinDbg is good to understand how the computer works! Visual Studio is like a Dinosaurus I use it with C# and MySql, time is missing to discover more in detail Ghydra or X64dbg by example, Linux and Mac OS with Xcode and Swift (C#) I try to stay close with. I'd like to understand a little bit more Rust, Cargo, Truffle, Solidity, so interested too in network, cybersecurity...devops! Saas is a good oportunity as well as cryptography and algorythmic to discover and learn softwares protections like software licence key server! In fact computing is part of my life since years 1985 with Atari-Amiga-Amstrad! You, buddies? Regards! Thierry
Since I have updated .json in v.s. code #include <sal.h> is not necessary anymore winuser was a bad idea! C/C++ under UNIX seems to be very interesting too because of the processor installed into Sun servers! Bye-bye
Topic archived. No new replies allowed.