Dziwny błąd w MS VC++ 2010

0

Witam!
Mam taki problem. Otóż napisałem taki kod, którego za nic nie mogę uruchomić. Tak czy siak wywala błąd a kod jet poprawny.

#include <Windows.h>

HINSTANCE hInst;  //global handle to hold the application instance
HWND wndHandle;   //global variable to hold the window handle

//initWindow registers the window class for the application, creates the window
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
bool initWindow(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	//Fill in the WNDCLASSEX structure. This describes how the window will look to the system
	wcex.cbSize			= sizeof(WNDCLASSEX); //the size of the structure
	wcex.style			= CS_HREDRAW | CS_VREDRAW; //the class style
	wcex.lpfnWndProc	= (WNDPROC)WndProc; //the window procedure callback
	wcex.cbClsExtra		= 0; //extra bytes to allocate for this class
	wcex.cbWndExtra		= 0; //extra bytes to allocate for this instance
	wcex.hInstance		= hInstance; //handle to the application instance
	wcex.hIcon			= 0; //icon to associate with the application
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW); //the default cursor
	wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1); //the background color
	wcex.lpszMenuName	= NULL; //the resource name for the menu
	wcex.lpszClassName	= "DirectXExample"; //the class name being created
	wcex.hIconSm		= 0; //the handle to the small icon
	RegisterClassEx(&wcex);


	//Create the window
	wndHandle = CreateWindow(
					"DirectXExample",		//the window class to use
					"DirectXExample",		//the title bar text
					WS_OVERLAPPEDWINDOW,	//the window style
					CW_USEDEFAULT,			//the starting x coordinate
					CW_USEDEFAULT,			//the starting y coordinate
					640,					//the pixel width of the window
					480,					//the pixel height of the window
					NULL,					//the parent window; NULL for desktop
					NULL,					//the menu for the application; NULL for none
					hInstance,				//the handle to the application instance
					NULL);					//no values passed to the window

	//Make sure that the window handle that is created is valid
	if(!wndHandle)
			return false;

	//Display the window on the screen
	ShowWindow(wndHandle, SW_SHOW);
	UpdateWindow(wndHandle);
	return true;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	//Initialize the window
/*	if(!initWindow(hInstance))
			return false;*/

	// Main message loop
	MSG msg;
	ZeroMemory(&msg,sizeof(msg));
	while(msg.message!=WM_QUIT)
	{
		//Check the message queue
		while(GetMessage(&msg, wndHandle, 0, 0))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return (int) msg.wParam;
}

No i błąd:

1>------ Build started: Project: example1poprawka, Configuration: Debug Win32 ------
1>  winmain.cpp
1>winmain.obj : error LNK2019: unresolved external symbol "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function "bool __cdecl initWindow(struct HINSTANCE__ *)" (?initWindow@@YA_NPAUHINSTANCE__@@@Z)
1>c:\users\łukasz\documents\visual studio 2010\Projects\example1poprawka\Debug\example1poprawka.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ktoś wie o co chodzi? Dodam, że zmieniałem kodowanie projektu z Unicode na Multi-Byte. Przy ustawieniu na Unicode sprawa wygląda tak:

1>------ Build started: Project: example1poprawka, Configuration: Debug Win32 ------
1>  winmain.cpp
1>c:\users\łukasz\documents\visual studio 2010\projects\example1poprawka\example1poprawka\winmain.cpp(23): error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\łukasz\documents\visual studio 2010\projects\example1poprawka\example1poprawka\winmain.cpp(40): error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\łukasz\documents\visual studio 2010\projects\example1poprawka\example1poprawka\winmain.cpp(54): error C2731: 'WinMain' : function cannot be overloaded
1>          c:\users\łukasz\documents\visual studio 2010\projects\example1poprawka\example1poprawka\winmain.cpp(53) : see declaration of 'WinMain'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Nie wiem co dalej robić...

1

A gdzie masz tą LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); ?
Przy unicode musisz ciągi znaków poprzedzać literką L, np:
wcex.lpszClassName = L"DirectXExample"; //the class name being created

0

zmien
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
na
WNDPROC WndProc;

1

Jeśli chcesz żeby kod się kompilował zarówno jako multi-byte jak i unicode, możesz użyć makra TEXT do wszystkich stringów używanych w WinAPI:

wcex.lpszClassName = TEXT("DirectXExample");

Ale czy to ma sens? multi-byte było potrzebne dla Win9x, a że program skompilowany pod VS2010 i tak nie ma szans ruszyć pod 9x z innych powodów, to proponuję trzymać się unikodu, a multi-byte traktować jako relikt przeszłości.

0

Wielkie dzięki! Pozmieniałem i teraz mi śmiga :)

Ale mam kolejny problem... Mianowicie taki fragment kodu:

	pd3dDevice->CreateOffscreenPlainSurface( 491,
						 424,
						 D3DFMT_X8R8G8B8,
						 D3DPOOL_DEFAULT,
						 &srcSurface,
						 NULL );


	D3DXLoadSurfaceFromFile( srcSurface,
					 NULL,
					 NULL,
					 "C:\\img\\plaza.bmp",
					 NULL,
					 D3DX_DEFAULT,
					 0,
					 NULL );

No i teraz podkreśla mi D3DXLoadSurfaceFromFile oraz D3DX_DEFAULT. I oba wg niego są undefined mimo, że są one w bibliotece d3d9.h, którą mam zaincludowaną i podlinkowaną...

0

Postanowiłem się zarejestrować.

Patrzyłem tam ale nic nie znalazłem pomocnego...

1

przechwytywanie.png

0

Próbowałem i niby nie mogę dodać tej biblioteki... Jakby jej w ogóle nie było.

edit:
Problem rozwiązany. Taki ze mnie noob, bo katalogów nie miałem ustawionych :D

1 użytkowników online, w tym zalogowanych: 0, gości: 1