4 Replies - 591 Views - Last Post: 25 June 2013 - 09:02 AM Rate Topic: -----

#1 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 31-July 12

DXGuid.lib linking problem

Posted 24 June 2013 - 06:45 PM

Hey there guys! I have been following the tutorials in the Beginning Game Programming third edition by Jonathan S. Harbour. In the 5th chapter is a bomb catching game demo tutorial. Now I have written the code, compiled it, debugged it (many times) and now the only problem I have left (to my frustration) is the lnk1104 error. It seems that my compiler can not link to the dxguid library. The internet has proven unfruitful in my quest to get this code working and I have not a clue about the dxguid library. Here is the codes for the lesson:

Mywindow.cpp


#include "MyDirectX.h"
using namespace std;
bool gameover = false;

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_DESTROY:
			gameover = true;
			PostQuitMessage(0);
			return 0;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = (WNDPROC)WinProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = NULL;
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = APPTITLE.c_str();
	wc.hIconSm       = NULL;
	RegisterClassEx(&wc);

	HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREENW, SCREENH, NULL, NULL, hInstance, NULL);
	if (window == 0) return 0;

	ShowWindow(window, nCmdShow);
	UpdateWindow(window);

	if(!Game_Init(window)) return 0;

	MSG message;
	while (!gameover)
	{
		if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&message);
			DispatchMessage(&message);
		}

		Game_Run(window);

	}
	Game_End();
	return message.wParam;
}



MyDirectX.h

#pragma once

#define WIN32_EXTRA_LEAN
#define DIRECTINPUT_VERSION 0x0800
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>
#include <XInput.h>
#include <ctime>
#include <iostream>
#include <iomanip>
using namespace std;

#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "xinput.lib")

extern const string APPTITLE;
extern const int SCREENW;
extern const int SCREENH;
extern bool gameover;

extern LPDIRECT3D9 d3d;
extern LPDIRECT3DDEVICE9 d3ddev;
extern LPDIRECT3DSURFACE9 backbuffer;

bool Direct3D_Init(HWND hWnd, int width, int height, bool fullscreen);
void Direct3D_Shutdown();
LPDIRECT3DSURFACE9 LoadSurface(string filename);
void DrawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source);

extern LPDIRECTINPUT8 dinput;
extern LPDIRECTINPUTDEVICE8 dimouse;
extern LPDIRECTINPUTDEVICE8 dikeyboard;
extern DIMOUSESTATE mouse_state;
extern XINPUT_GAMEPAD controllers[4];

bool DirectInput_Init(HWND);
void DirectInput_Update();
void DirectInput_Shutdown();
int Key_Down(int);
int Mouse_Button(int);
int Mouse_X();
int Mouse_Y();
void XInput_Vibrate(int coutNum = 0, int amount = 65535);
bool XInput_Controller_Found();

bool Game_Init(HWND window);
void Game_Run (HWND window);
void Game_End();



MyDirectX.cpp

#include "MyDirectX.h"
#include <iostream>
using namespace std;

LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DSURFACE9 backbuffer = NULL;

LPDIRECTINPUT8 dinput = NULL;
LPDIRECTINPUTDEVICE8 dimouse = NULL;
LPDIRECTINPUTDEVICE8 dikeyboard = NULL;
DIMOUSESTATE mouse_state;
char keys[256];
XINPUT_GAMEPAD controllers[4];

bool Direct_Init(HWND window, int width, int height, bool fullscreen)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);
	if (!d3d) return false;

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = (!fullscreen);
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = width;
	d3dpp.BackBufferHeight = height;
	d3dpp.hDeviceWindow = window;

	d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
	if (!d3ddev) return false;

	d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

	return true;
}

void Direct3D_Shutdown()
{
	if(d3ddev) d3ddev->Release();
	if(d3d) d3d->Release();
}

void DrawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source)
{
	D3DSURFACE_DESC desc;
	source -> GetDesc(&desc);

	RECT source_rect = {0, 0, (long)desc.Width, (long)desc.Height};
	RECT dest_rect = {(long)x, (long)y, (long)x+desc.Width, (long)y+desc.Height};

	d3ddev->StretchRect(source, &source_rect, dest, &dest_rect, D3DTEXF_NONE);
}

LPDIRECT3DSURFACE9 LoadSurface(string filename)
{
	LPDIRECT3DSURFACE9 image = NULL;

	D3DXIMAGE_INFO info;
	HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info);
	if (result != D3D_OK) return NULL;

	result = d3ddev->CreateOffscreenPlainSurface(info.Width, info.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &image, NULL);

	if (result != D3D_OK) return NULL;

	result = D3DXLoadSurfaceFromFile(image, NULL, NULL, filename.c_str(), NULL, D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL);

	if(result != D3D_OK) return NULL;

	return image;
}

bool DirectInput_Init (HWND hWnd)
{
	HRESULT result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&dinput, NULL);

	dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
	dikeyboard->SetDataFormat(&c_dfDIKeyboard);
	dikeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);

	dikeyboard->Acquire();

	dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);
	dimouse->SetDataFormat(&c_dfDIMouse);
	dimouse->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);

	dimouse->Acquire();
	d3ddev->ShowCursor(false);

	return true;

}

void DirectInput_Update()
{
	dimouse->GetDeviceState(sizeof(mouse_state), (LPVOID)&mouse_state);

	dikeyboard->GetDeviceState(sizeof(keys), (LPVOID)&keys);

	for (int i = 0; i < 4; i++)
	{
		ZeroMemory(&controllers[i], sizeof(XINPUT_STATE));

		XINPUT_STATE state;
		DWORD result = XInputGetState(i, &state);

		if(result == 0) controllers[i] = state.Gamepad;
	}
}

int Mouse_X()
{
	return mouse_state.lX;
}

int Mouse_Y()
{
	return mouse_state.lY;
}

int Mouse_Buttons(int button)
{
	return mouse_state.rgbButtons[button] & 0x80;
}

int Key_Down(int key)
{
	return (keys[key] & 0x80);
}

void DirectInput_Shutdown()
{
	if (dikeyboard)
	{
		dikeyboard->Unacquire();
		dikeyboard->Release();
		dikeyboard = NULL;
	}

	if (dimouse)
	{
		dimouse->Unacquire();
		dimouse->Release();
		dimouse = NULL;
	}
}

bool XInput_Controller_Found()
{
	XINPUT_CAPABILITIES caps;
	ZeroMemory(&caps, sizeof(XINPUT_CAPABILITIES));
	XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &caps);
	if (caps.Type != 0) return false;

	return true;
}

void XInput_Vibrate(int contNum, int amount)
{
	XINPUT_VIBRATION vibration;
	ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));
	vibration.wLeftMotorSpeed = amount;
	vibration.wRightMotorSpeed = amount;
	XInputSetState(contNum, &vibration);
}



and MyGame.cpp


#include "MyDirectX.h"
using namespace std;

const string APPTITLE = "Bomb Catcher Game";
const int SCREENW = 1024;
const int SCREENH = 768;

LPDIRECT3DSURFACE9 bomb_surf = NULL;
LPDIRECT3DSURFACE9 bucket_surf = NULL;

struct BOMB 
{
	float x, y;

	void reset()
	{
		x = (float)(rand() % (SCREENW - 128));
		y = 0;
	}
};

	BOMB bomb;

	struct BUCKET
	{
		float x, y;
	};

	BUCKET bucket;

	int score = 0;
	int vibrating = 0;

	bool Game_Init(HWND window)
	{
		Direct3D_Init(window, SCREENW, SCREENH, false);

		DirectInput_Init(window);

		bomb_surf = LoadSurface("bomb.bmp");
		if (!bomb_surf)
		{
			MessageBox(window, "Error loading bomb", "Error", 0);
			return false;
		}

		bucket_surf = LoadSurface("bucket.bmp");
		if (!bucket_surf)
		{
			MessageBox(window, "Error loading bucket", "Error", 0);
			return false;
		}

		d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

		srand((unsigned int)time(NULL));
		bomb.reset();

		bucket.x = 500;
		bucket.y = 630;
		return true;

	}

	void Game_Run(HWND window)
	{
		if(!d3ddev) return;

		DirectInput_Update();

		bomb.y += 2.0f;

		if(bomb.y > SCREENH)
		{
			MessageBox(0, "Oh no, the bombb exploded!!", "YOU STINK", 0);
			gameover = true;
		}

		int mx = Mouse_X();
		if (mx < 0) bucket.x -= 6.0f;
		else if (mx > 0) bucket.x += 6.0f;

		if (Key_Down(DIK_LEFT)) bucket.x -= 6.0f;
		else if (Key_Down(DIK_RIGHT)) bucket.x += 6.0f;

		if (XInput_Controller_Found())
		{
			if (controllers[0].sThumbLX < -5000)
				bucket.x -= 6.0f;
			else if (controllers[0].sThumbLX > 5000)
				bucket.x += 6.0f;

			if (controllers[0].bLeftTrigger > 128)
				bucket.x -= 6.0f;
			else if (controllers[0].bRightTrigger > 128)
				bucket.x += 6.0f;

			if (controllers[0].wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)
				bucket.x -= 6.0f;
			else if (controllers[0].wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)
				bucket.x += 6.0f;

			if (controllers[0].wButtons & XINPUT_GAMEPAD_DPAD_LEFT)
				bucket.x -= 6.0f;
			else if (controllers[0].wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)
				bucket.x += 6.0f;
		}

		if (vibrating > 0)
		{
			vibrating++;
			if (vibrating > 20)
			{
				XInput_Vibrate(0, 0);
				vibrating = 0;
			}
		}

		if (bucket.x < 0) bucket.x = 0;
		if (bucket.x > SCREENW-128) bucket.x = SCREENW-128;

		int cx = bomb.x + 64;
		int cy = bomb.y + 64;
		if (cx > bucket.x && cx < bucket.x+128 && cy > bucket.y && cy < bucket.y+128)
		{
			score++;
			char s[255];
			sprintf(s, "%s [SCORE %d]", APPTITLE.c_str(), score);
			SetWindowText(window, s);

			XInput_Vibrate (0, 65000);
			vibrating = 1;

			bomb.reset();
		}

		d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0,0,0));

		if (d3ddev->BeginScene())
		{
			DrawSurface(backbuffer, bomb.x, bomb.y, bomb_surf);
	
			DrawSurface(backbuffer, bucket.x, bucket.y, bucket_surf);

			d3ddev->EndScene();
			d3ddev->Present(NULL, NULL, NULL, NULL);
		}	

		if (Key_Down(DIK_ESCAPE))
			gameover = true;

		if (controllers[0].wButtons & XINPUT_GAMEPAD_BACK)
			gameover = true;
	}

	void Game_End()
	{
		if (bomb_surf) bomb_surf->Release();
		if (bucket_surf) bucket_surf->Release();
		DirectInput_Shutdown();
		Direct3D_Shutdown();
	}



The only difference that I can tell by looking at the book is that he is (probably) using Visual Studios C++ 2008 pro, and I'm using Visual Studio C++ 2010 express. I do not think that should be a problem but what do I know. Please some guidance will be much appreciated, and yes I am aware that most of my posts are cries for help; but I only come here looking for help after I have tried (many times) to solve the problem on my own. Thanks for all the time, patience, and help with this noob programmer. :)/>

Is This A Good Question/Topic? 0
  • +

Replies To: DXGuid.lib linking problem

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: DXGuid.lib linking problem

Posted 24 June 2013 - 08:56 PM

Where is dxguid.lib listed in your project settings?
Was This Post Helpful? 0
  • +
  • -

#3 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 31-July 12

Re: DXGuid.lib linking problem

Posted 25 June 2013 - 04:14 AM

View PostButchDean, on 24 June 2013 - 10:56 PM, said:

Where is dxguid.lib listed in your project settings?


Nowhere, I followed the book but it did not say anything about placing that library somewhere. I did try adding it to my additional dependencies, but that did not work either.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: DXGuid.lib linking problem

Posted 25 June 2013 - 08:51 AM

Ensure that this is in your additional dependencies

dxguid.lib



and additional library directories

$(DXSDK_DIR)\Lib\x86



$(DXSDK_DIR)\Lib\x64



But I do worry that you will struggle with DirectX if this has stumped you. What other experience do you have?
Was This Post Helpful? 0
  • +
  • -

#5 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: DXGuid.lib linking problem

Posted 25 June 2013 - 09:02 AM

Exactly. Books do require a prerequisite knowledge before reading them, like knowing how to overcome problems like this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1