#define WIN32_LBAN_AND_MBAN
#include <windows.h>


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

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX windowClass;
	ZeroMemory(&windowClass, sizeof(WNDCLASSEX));

	windowClass.cbSize = sizeof(WNDCLASSEX);
	windowClass.style = CS_HREDRAW | CS_VREDRAW;
	windowClass.lpfnWndProc = (WNDPROC)WindowProc;
	windowClass.hInstance = hInstance;
	windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	windowClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
	windowClass.lpszClassName = "WindowClass";

	RegisterClassEx(&windowClass);

	HWND windowHandle = CreateWindowEx(NULL, "WindowClass", "WindowClass", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, NULL, NULL, hInstance, NULL);

	ShowWindow(windowHandle, nShowCmd);
	UpdateWindow(windowHandle);

	MSG msg;

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}
}

That's my code, i got it from an online tutorial so i have absolutely no clue why its not compiling other than my errors...

1>------ Build started: Project: Drunken_hyena, Configuration: Debug Win32 ------
1>  drunken_hyena.cpp
1>c:\users\konnor\documents\visual studio 2010\projects\drunken_hyena\drunken_hyena\drunken_hyena.cpp(18): error C2440: '=' : cannot convert from 'const char [12]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\konnor\documents\visual studio 2010\projects\drunken_hyena\drunken_hyena\drunken_hyena.cpp(22): error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The win32 API requires wide-char strings. You need to add a leading L in front of the literal string to tell the compiler to create a wide-char literal string:

windowClass.lpszClassName = L"WindowClass"; //notice the L in front.

And similarly for the other place where the error occurs.

The win32 API requires wide-char strings. You need to add a leading L in front of the literal string to tell the compiler to create a wide-char literal string:

windowClass.lpszClassName = L"WindowClass"; //notice the L in front.

And similarly for the other place where the error occurs.

Thanks, it worked! =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.