Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Problem with compiler setup

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

I think somethings wrong with the setup, but im not sure what. my friend wrote some code that doesnt compile on my pc but compiles fine on his. also several examples from the internet generate errors simmilar to the ones ive gotten. all the errors relate to this file, grid.cpp:
//////////////////////////////////////////////////////////////////////
// Grid.cpp : Defines the entry point for the application.
//

// Includes
#include "stdafx.h"

// Prototypes
long _stdcall WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
bool WaitFor(unsigned int Pause);
void Render(void);

// Standard globals
IDirect3D9*			pD3D;						// Interface for Direct3D
IDirect3DDevice9*	pDev;						// Interface for graphics device
HINSTANCE			hInst;						// Handle to application instance
HWND				hWnd;						// Handle to main application window
HFONT				FontHandle;					// Handle to text font
ID3DXFont*			Font;						// Font interface

// Game globals
char*					WindowTitle = "Grid";
Map						TheMap;
Character				Bloke;
IDirect3DTexture9*		Char;
IDirect3DTexture9*		Tile;
IDirect3DVertexBuffer9*	QuadBuffer;
VERT Quad[] = {
	{ -0.5f, 0.0f,  0.5f, 0.0f, 0.0f},
	{  0.5f, 0.0f,  0.5f, 1.0f, 0.0f},
	{ -0.5f, 0.0f, -0.5f, 0.0f, 1.0f},
	{  0.5f, 0.0f, -0.5f, 1.0f, 1.0f},
};

// Main
int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
	// Locals
	WNDCLASSEX		wc;
	MSG				msg;

	// Define window
	ZeroMemory(&wc, sizeof(WNDCLASSEX));
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.hInstance		= hInst = hInstance;
	wc.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_ICON);
	wc.hIconSm			= LoadIcon(hInstance, (LPCTSTR)IDI_ICON);
	wc.hCursor			= LoadCursor(hInst, (LPCTSTR)IDC_ARROW);
	wc.lpszClassName	= "WINDOW";
	wc.lpfnWndProc		= (WNDPROC)WndProc;
	wc.style			= CS_CLASSDC;
	RegisterClassEx(&wc);

	// Create window
	hWnd = CreateWindowEx(
		WS_EX_TOPMOST, "WINDOW", WindowTitle, WS_OVERLAPPEDWINDOW ^ ( WS_THICKFRAME | WS_MAXIMIZEBOX ),
		100, 50, 647, 674, NULL, NULL, hInst, NULL);
	ShowWindow(hWnd, nShow);	// Bring window to foreground
	UpdateWindow(hWnd);			// Begin updating window
	
	// Initialize Direct3D
	pD3D = Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS Present;
	ZeroMemory(&Present, sizeof(Present));
	Present.SwapEffect					= D3DSWAPEFFECT_DISCARD;
	Present.MultiSampleType				= D3DMULTISAMPLE_NONE;
	Present.MultiSampleQuality			= 0;
	Present.FullScreen_RefreshRateInHz	= D3DPRESENT_RATE_DEFAULT;
	Present.AutoDepthStencilFormat		= D3DFMT_D24S8;
	Present.EnableAutoDepthStencil		= TRUE;
	Present.Windowed					= TRUE;
	Present.BackBufferWidth				= 640;
	Present.BackBufferHeight			= 640;
	Present.BackBufferFormat			= D3DFMT_X8R8G8B8;

	// Create device
	pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, 
		&Present, &pDev);
	pDev->SetRenderState(D3DRS_LIGHTING, FALSE);
	pDev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
	pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
	pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CONSTANT);
	pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

	// Set up a font for text	
	FontHandle = CreateFont(12, 0, 0, 0, 100, FALSE, FALSE, FALSE, 
		DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
		FF_DONTCARE, NULL);
	D3DXCreateFont(pDev, (HFONT)FontHandle, &Font);

	// Load textures
	D3DXCreateTextureFromFile(pDev, "Character.png", &Char);
	D3DXCreateTextureFromFile(pDev, "Tile.bmp", &Tile);

	// Buffer vertices
	void* pVert;
	pDev->CreateVertexBuffer(4*sizeof(VERT),
		0, FVF, D3DPOOL_DEFAULT, &QuadBuffer, NULL);
	QuadBuffer->Lock(0, sizeof(VERT)*4, (void**)&pVert, 0);
		memcpy(pVert, Quad, sizeof(VERT)*4);
	QuadBuffer->Unlock();

	// Set up stream source
	pDev->SetStreamSource(0, QuadBuffer, 0, sizeof(VERT));
	pDev->SetFVF(FVF);

	// Set up projection matrix
	D3DXMATRIX Proj;
	D3DXMatrixOrthoLH(&Proj, 16.0f, 16.0f, 1.0f, 32.0f);
	pDev->SetTransform(D3DTS_PROJECTION, &Proj);

	// Set up view matrix
	D3DXMATRIX View;
	D3DXMatrixLookAtLH(&View, 
		&D3DXVECTOR3(0.0f, 16.0f, 0.0f), 
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f), 
		&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	pDev->SetTransform(D3DTS_VIEW, &View);

	// Set up world matrix
	D3DXMATRIX World;
	D3DXMatrixIdentity(&World);
	pDev->SetTransform(D3DTS_WORLD, &World);

	// Load in the map
	TheMap.LoadMapFromBitmap("Map.bmp");
	Bloke.SetPosition(5, 3);
	Bloke.SetColour(0xFFFFFF00);

	// Enter game loop
	bool Done = FALSE;
	while(!Done)
	{
		if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
		{
			// Check for exit message
			if(msg.message == WM_QUIT)
				Done = TRUE;

			// Handle windows messages
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{				
			// sync to 50 frames per second
			if(WaitFor(20))
			{			
				// Render scene
				Render();
			}
		}
	}

	// Cleanup and exit
	UnregisterClass("WINDOW", hInst);
	return 0;
}

// Functions
long _stdcall WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	// Message switch
	switch(msg)
	{
		case WM_SYSCOMMAND :
			// Handle system commands
			switch(wparam)
			{
				case SC_MONITORPOWER :
				case SC_SCREENSAVE :
					return 0;
			}
			break;
		case WM_DESTROY :
			// Destroy window
			PostQuitMessage(0);
			return 0;
		case WM_KEYUP :
			if(wparam == VK_ESCAPE)
				DestroyWindow(hWnd);
			return 0;
		case WM_KEYDOWN :
			if(wparam == VK_DOWN)
			{
				if(TheMap.CheckLocation(Bloke.GetX(), Bloke.GetY()+1))
					Bloke.Move(0, 1);
			}
			if(wparam == VK_UP)
			{
				if(TheMap.CheckLocation(Bloke.GetX(), Bloke.GetY()-1))
					Bloke.Move(0, -1);
			}
			if(wparam == VK_LEFT)
			{
				if(TheMap.CheckLocation(Bloke.GetX()-1, Bloke.GetY()))
					Bloke.Move(-1, 0);
			}
			if(wparam == VK_RIGHT)
			{
				if(TheMap.CheckLocation(Bloke.GetX()+1, Bloke.GetY()))
					Bloke.Move(1, 0);
			}
			return 0;
	}

	return DefWindowProc(hwnd, msg, wparam, lparam);
}

bool WaitFor(unsigned int Pause)
{
	// Create a counter	
	static unsigned int LastFrame = 0;
	unsigned int CurrentTime = 0;
	unsigned int Ellapsed = 1;

	// Update current time
	CurrentTime = timeGetTime();
	Ellapsed = CurrentTime - LastFrame;

	// Check if enough time has ellapsed
	if(Ellapsed >= Pause)
	{
		// Update last frame time
		LastFrame = CurrentTime;
		return TRUE;
	}

	return FALSE;
}

void Render(void)
{
	// Clear screen
	pDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

	// Create scene
	if(SUCCEEDED(pDev->BeginScene()))
	{
		// Move camera
		D3DXMATRIX View;
		D3DXMatrixLookAtLH(&View, 
			&D3DXVECTOR3((float)Bloke.GetX(), 16.0f, -(float)Bloke.GetY()-0.5f), 
			&D3DXVECTOR3((float)Bloke.GetX(), 0.0f, -(float)Bloke.GetY()-0.5f), 
			&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
		pDev->SetTransform(D3DTS_VIEW, &View);

		// Render all objects
		TheMap.Render();
		Bloke.Render();

		// End scene
		pDev->EndScene();
	}

	// Present
	pDev->Present(NULL, NULL, NULL, NULL);
}

// Map class
Map::Map()
{

}

Map::~Map()
{

}

void Map::Render(void)
{			
	//  Locals
	D3DXMATRIX World;
	int ix, iy;

	// Load map texture
	pDev->SetTexture(0, Tile);

	// Draw accessible areas
	pDev->SetTextureStageState(0, D3DTSS_CONSTANT, 0xFF007FFF);	
	for(iy=0; iy<64; iy++)
	{
		for(ix=0; ix<64; ix++)
		{
			if(this->CheckLocation(ix, iy))
			{
				D3DXMatrixTranslation(&World, (float)ix, 0.0f, (float)-iy);
				pDev->SetTransform(D3DTS_WORLD, &World);
				pDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
			}
		}
	}

	// Draw inaccessible areas
	pDev->SetTextureStageState(0, D3DTSS_CONSTANT, 0xFFFF0000);	
	for(iy=0; iy<64; iy++)
	{
		for(ix=0; ix<64; ix++)
		{
			if(!this->CheckLocation(ix, iy))
			{
				D3DXMatrixTranslation(&World, (float)ix, 0.0f, (float)-iy);
				pDev->SetTransform(D3DTS_WORLD, &World);
				pDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
			}
		}
	}
}

void Map::LoadMapFromBitmap(char* FileName)
{
	// Locals
	BITMAPFILEHEADER bmfh;
	BITMAPINFOHEADER bmih;

	// Read the bitmap file into the grid
	FILE* pFile = fopen(FileName, "rb");
	{
		// Check that file will work
		if(!this->CheckBitmap(&bmfh, &bmih, pFile))
		{
			fclose(pFile);
			MessageBox(NULL, "Invalid bitmap format\n\nBitmap must be 24-bit colour and have\n dimensions of 64x64 pixels.", "Error", MB_OK | MB_ICONERROR);
			return;
		}

		// Read bitmap into array
		for(int y=0; y<64; y++)
		{
			for(int x=0; x<64; x++)
			{
				// Read the date
				DWORD Buffer = 0;
				fread(&Buffer, 1, 3, pFile);

				// Check if the grid reference is true or false
				if(Buffer != 0)	this->Grid[x][63-y] = TRUE;
				else			this->Grid[x][63-y] = FALSE;
			}
		}
	}
	fclose(pFile);
}

bool Map::CheckLocation(int x, int y)
{
	// Check that the request is within the bounds of the map
	if((x>0)&&(x<64)&&(y>0)&&(y<64))
	{
		return this->Grid[x][y];
	}

	// Default return
	return FALSE;
}

bool Map::CheckBitmap(BITMAPFILEHEADER* pBmfh, BITMAPINFOHEADER* pBmih, FILE* pFile)
{
	// Check if file is a bitmap file
	fread(pBmfh, sizeof(BITMAPFILEHEADER), 1, pFile);
	if(pBmfh->bfType != 0x4D42)				return FALSE;

	// Check bit count		
	fread(pBmih, sizeof(BITMAPINFOHEADER), 1, pFile);
	if(pBmih->biBitCount != 24)				return FALSE;

	// Check dimensions 
	if(pBmih->biWidth	!= 64)				return FALSE;
	if(pBmih->biHeight	!= 64)				return FALSE;

	// File is acceptable 
	return TRUE;
}

Character::Character()
{

}

Character::~Character()
{

}

int Character::GetX(void)	{ return this->x;	}
int Character::GetY(void)	{ return this->y;	}

void Character::Render(void)
{
	//  Locals
	D3DXMATRIX World;

	// Load map texture
	pDev->SetTexture(0, Char);

	// Draw accessible areas
	pDev->SetTextureStageState(0, D3DTSS_CONSTANT, this->Colour);

	// Draw quad
	D3DXMatrixTranslation(&World, (float)this->x, 0.5f, (float)-this->y);
	pDev->SetTransform(D3DTS_WORLD, &World);
	pDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}

void Character::Move(int mx, int my)
{
	// Locals 
	int StepX = this->x + mx; 
	int StepY = this->y + my;

	// Check that the request is within the bounds of the map
	if((StepX>0)&&(StepX<64)&&(StepX>0)&&(StepX<64))
	{
		if(TheMap.CheckLocation(StepX, StepY))
		{
			this->x = StepX;
			this->y = StepY;
		}
	}
}

void Character::SetPosition(int px, int py)
{
	// Check that the request is within the bounds of the map
	if((px>0)&&(px<64)&&(py>0)&&(py<64))
	{
		if(TheMap.CheckLocation(px, py))
		{
			this->x = px;
			this->y = py;
		}
	}
}

void Character::SetColour(DWORD argb)
{
	this->Colour = argb;
}



errors:
------ Build started: Project: Grid, Configuration: Debug Win32 ------
Compiling...
Grid.cpp
c:\documents and settings\martin\desktop\grid\grid.cpp(49) : error C2440: '=' : cannot convert from 'const char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\martin\desktop\grid\grid.cpp(57) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\martin\desktop\grid\grid.cpp(95) : error C2660: 'D3DXCreateFontW' : function does not take 3 arguments
c:\documents and settings\martin\desktop\grid\grid.cpp(98) : error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\martin\desktop\grid\grid.cpp(99) : error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\martin\desktop\grid\grid.cpp(162) : error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\martin\desktop\grid\grid.cpp(213) : warning C4244: 'return' : conversion from 'LRESULT' to 'long', possible loss of data
c:\documents and settings\martin\desktop\grid\grid.cpp(330) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [90]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\Martin\Desktop\Grid\Debug\BuildLog.htm"
Grid - 7 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
Advertisement
I'm guessing you're using MSVC .NET 2005. Go to your project properties. Under General there should be an option named Character Set. Change that to use Multibyte Character Set.

Share this post


Link to post
Share on other sites
I'm curious which option it is if you find it. My workaround was to use wide string literals (prefix the string with L, e.g. L"something or another").

Share this post


Link to post
Share on other sites
Well create font still throws up an error, but the big chunk of problems is out of the way.

thanks a lot for the help!

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!