Jump to content
  • Advertisement
Sign in to follow this  
Samsonite

Error when initializing window

This topic is 4869 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

Hello! I have some problems compiling my DX window in Visual Studio 2005 Beta 2:
------ Build started: Project: example1, Configuration: Debug Win32 ------
Compiling...
winmain.cpp
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(12) : error C2065: 'WndProc' : undeclared identifier
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(20) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(24) : error C2065: 'wndHandle' : undeclared identifier
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(24) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(34) : error C2365: 'WndProc' : redefinition; previous definition was 'formerly unknown identifier'
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(45) : warning C4007: 'WinMain' : must be '__stdcall'
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(55) : error C2143: syntax error : missing ')' before '{'
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(55) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Build log was saved at "file://c:\Documents and Settings\Øyvind Ege\Mine dokumenter\Visual Studio 2005\Projects\example1\example1\Debug\BuildLog.htm"
example1 - 7 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And here's my code:
#include <windows.h>

HINSTANCE hInst;
HWND wnHandle;

bool initWindow( HINSTANCE hInstance )
{
	WNDCLASSEX wcex;

	wcex.cbSize			=sizeof( WNDCLASSEX );
	wcex.style			=CS_HREDRAW| CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra     = 0;
	wcex.cbWndExtra     = 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW);
	wcex.lpszMenuName   = NULL;
	wcex.lpszClassName  = "DirectXExample";
	wcex.hIconSm		= 0;
	RegisterClassEx(&wcex);

	wndHandle = CreateWindow("DirectXExample", "DirectXExample",WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
	if(!wndHandle)
		return false;

	ShowWindow(&wndHandle, SW_SHOW);
	UpdateWindow(wndHandle);
	return true;
}

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

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	if (!initWindow(hInstance) )
		return false;

	MSG msg;

	ZeroMemory( &msg, sizeof(msg ) );
	while( msg.message!=WM_QUIT)
	{
		while (GetMessage(&msg, wndHandle, 0, 0)
		{
			TranslateMessage(&msg);
			DispatchMessage8&msg);
		}
	}
	return (int) msg.wParam;
}

Thanks for any help!

Share this post


Link to post
Share on other sites
Advertisement
1. Insert line:

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

befine WinMain(). This is called predeclaration (or something else). Whdn compiler hits WndProc usage in WinMain, it doesn't yet know about it.

Share this post


Link to post
Share on other sites
2. Turn off unicode in your project settings. Right-click on your project, select properties. In the "General" tab find "Character Set" and select "Use Multi-Byte Character Set".

!EDIT! yes.

3. You made a typo: "HWND wnHandle" -> "HWND wndHandle"

!EDIT! oops. It is named initWindow. Then before initWindow.

4. Change "int WinMain" to "int WINAPI WinMain".

5. You forgot an extra round brace after "while (GetMessage(&msg, wndHandle, 0, 0)".

Share this post


Link to post
Share on other sites
Now i get these errors:


------ Build started: Project: example1, Configuration: Debug Win32 ------
Compiling...
winmain.cpp
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(26) : error C2065: 'wndHandle' : undeclared identifier
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(47) : warning C4007: 'WinMain' : must be '__stdcall'
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(57) : error C2143: syntax error : missing ')' before '{'
c:\documents and settings\øyvind ege\mine dokumenter\visual studio 2005\projects\example1\example1\winmain.cpp(57) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Build log was saved at "file://c:\Documents and Settings\Øyvind Ege\Mine dokumenter\Visual Studio 2005\Projects\example1\example1\Debug\BuildLog.htm"
example1 - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!