• Advertisement
Sign in to follow this  

Nothing wrong with code, but wont compile?

This topic is 3674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

1>------ Build started: Project: 01 - Windows, Configuration: Debug Win32 ------ 1>Compiling... 1>winmain.cpp 1>c:\users\administrator\documents\visual studio 2008\projects\01 - windows\01 - windows\winmain.cpp(18) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\users\administrator\documents\visual studio 2008\projects\01 - windows\01 - windows\winmain.cpp(37) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>Build log was saved at "file://c:\Users\Administrator\Documents\Visual Studio 2008\Projects\01 - Windows\01 - Windows\Debug\BuildLog.htm" 1>01 - Windows - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include <windows.h>

LRESULT CALLBACK WindowEvent(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevhinstance, LPSTR commandline, int showstyle)
{
	WNDCLASSEX wc;

	wc.cbClsExtra = 0;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance = hinstance;
	wc.lpfnWndProc = WindowEvent;
	wc.lpszClassName = "MyClass";
	wc.lpszMenuName = NULL;
	wc.style = CS_VREDRAW | CS_HREDRAW;

	RegisterClassEx(&wc);

	HWND hwnd;
	hwnd = CreateWindowEx(
				NULL,
				"MyClass",
				"My Window",
				WS_OVERLAPPEDWINDOW | WS_VISIBLE,
				0,
				0,
				1024,
				768,
				NULL,
				NULL,
				hinstance,
				NULL);

	if (!hwnd)
		return 0;
	
	UpdateWindow(hwnd);

	MSG msg;
	while (true)
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message = WM_QUIT)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		//Process game here
	}
	
	
	return (int)msg.wParam;
}

LRESULT CALLBACK WindowEvent(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	}
	return DefWindowProc(hwnd,msg,wparam,lparam);
}

Share this post


Link to post
Share on other sites
Advertisement
You are compiling with wide-character support but are using non-wide characters. Either change from unicode to "not set" in the project options or use _T("foobar") instead of "foobar".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement