WinMain Function cannot be overloaded

Hi there,

I'm learning DirectX 11 at university, and we've been told to find a sample piece of code just to open a DirectX 11 window when the code is executed. And then study it to understand what's going on.

I managed to find a sample piece of code to open a window, but I'm having the error WinMain Function cannot be overloaded.
I've been searching around and playing around with the code but cannot seem to find a solution.

Code is shown below;
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
#include <windows.h>
#include <windowsx.h>

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPCSTR lpCmdLine, int nCmdShow)
{
	//the handle for the window, filled by a function
	HWND hWnd;
	//this struct holds information for the window class
	WNDCLASSEX wc;

	//clear out the window class for use
	ZeroMemory(&wc, sizeof(WNDCLASSEX));

	//fill in the struct with the needed information
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszClassName = L"WindowClass1";

	//Register the window class
	RegisterClassEx(&wc);

	//create the window and use the result as the handle
	hWnd = CreateWindowEx(NULL,
		L"WindowClass1",
		L"Our First Windowed Program",
		WS_OVERLAPPEDWINDOW,
		300,
		300,
		500,
		400,
		NULL,
		NULL,
		hInstance,
		NULL);

	//display the window on the screen
	ShowWindow(hWnd, nCmdShow);

	//enter the main loop

	//this struct holds Windows Event Messages

	MSG msg;

	//wait for the next message in thr queue, store the result in 'msg'
	while (GetMessage(&msg, NULL, 0, 0))
	{
		//Translate keystroke messages into the right format
		TranslateMessage(&msg);

		//send the message to the WindowProc function
		DispatchMessage(&msg);
	}
	return msg.wParam;
	
}

//this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	//sort through and find what code to run for the message given
	switch (message)
	{
		//this message is read when the window is closed
	case WM_DESTROY:
	{
		//close the application entirely
		PostQuitMessage(0);
		return 0;
	} break;
	}
	//Handle any messages the switch statement didn't
	return DefWindowProc(hWnd, message, wParam, lParam);
}
Last edited on
The code seems to be ok though it's just a WIN API demo, it has nothing to do with DirectX 11.
How did you create the project?
I just set it up from an empty project.

I think the first part we need to be able to open a window, and then apply graphics at a later date. Pretty sure it's just understanding the code to make a window open (I believe).
Do you use Visual Studio and what version ?
If yes, did you set the SubSystem under Properties->All Options to Windows?
The third parameter in WinMain should be LPSTR, not LPCSTR.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559(v=vs.85).aspx

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
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
	// Initialize the window
        // ...

	// Initialize Direct3D and cleanup if failed
        // ...

        // main loop ( message loop )
	MSG msg = { 0 };
	while ( WM_QUIT != msg.message )
	{
		if ( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ) )
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else
		{
			// Render
		}
	}

	// Cleanup: Release the global COM objects, ...
        // ...

	return ( int )msg.wParam;
}
Last edited on
Topic archived. No new replies allowed.