DirectX9 compile errors

This is a discussion on DirectX9 compile errors within the Windows Programming forums, part of the Platform Specific Boards category; So, given that no one wanted to tackle the last post (and I don't blame you either-- it was a ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    46

    DirectX9 compile errors

    So, given that no one wanted to tackle the last post (and I don't blame you either-- it was a doozie!)... I decided I'd try to simplify things a bit, and stick to one file-- after all, I'm still learning the basics of DirectX 9 here...

    Again, I'm getting compile errors... Is anyone willing to take a stab at this (or be willing to refer me to someone/somehere who might know)?? It's driving me absolutely nuts, and I have no idea where to go now...

    Thanks!

    -Maxthecat

    Compile Errors (MS VS 6):
    C:\Program Files\Microsoft Visual Studio\MyProjects\d3dspriter\spritetest.cpp(15) : error C2146: syntax error : missing ';' before identifier 'sprite'
    C:\Program Files\Microsoft Visual Studio\MyProjects\d3dspriter\spritetest.cpp(15) : error C2501: 'LP3DXSPRITE' : missing storage-class or type specifiers
    C:\Program Files\Microsoft Visual Studio\MyProjects\d3dspriter\spritetest.cpp(15) : fatal error C1004: unexpected end of file found

    Code:
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <d3dx9core.h>
    #include <dinput.h>
    #include <windows.h>
    
    LPDIRECT3D9 d3d;
    LPDIRECT3DDEVICE9 d3ddev;
    LPDIRECT3DSURFACE9 backbuffer;
    
    
    //LPDIRECTSURFACE9 back;
    LPDIRECTINPUT8 dinput;
    LPDIRECTINPUTDEVICE8 dikeyboard;
    LP3DXSPRITE sprite;
    LPDIRECT3DTEXTURE9 texture;
    char keys[256];
    
    int Init_Direct3D(HWND);
    int Key_Down(int key);
    void Poll_Keyboard();
    int Game_Init(HWND);
    void Game_Run(HWND);
    //void Game_End(HWND);
    
    typedef struct {
    	int x, y;
    	int width, height;
    	int movex, movey;
    } SPRITE;
    
    SPRITE kitty;
    
    void Game_Run(HWND hwnd)
    {
    	if (d3ddev == NULL)
    		return;
    
    	Poll_Keyboard();
    	if (Key_Down(DIK_LEFT)
    		kitty.x -= kitty.movex;
    	
    	if (Key_Down(DIK_RIGHT)
    		kitty.x -= kitty.movey;
    	
    	if (Key_Down(DIK_ESCAPE)
    	{
    		PostMessage(hwnd, WM_DESTROY, 0, 0);
    	}
    
    	if (d3ddev->BeginScene())
    	{
    		d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0,0,0));
    		D3DXVECTOR3 position((float)kitty.x, (float)kitty.y, 0);
    		sprite->Draw(
    			texture,
    			NULL,
    			NULL,
    			NULL,
    			0,
    			position,
    			D3DCOLOR_XRGB(255,255,255);
    		sprite->End();
    		d3dev->EndScene();
    	}
    }
    
    int Game_Init(HWND hwnd)
    {
    	D3DXIMAGE_INFO d3dxImageInfo;
    
    	D3DXCreateTextureFromFileEx( d3ddev,
                                     "cat.bmp",
                                     96, // I had to set width manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
                                     96, // I had to set height manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
                                     1,   // Don't create mip-maps when you plan on using D3DXSPRITE. It throws off the pixel math for sprite animation.
                                     D3DPOOL_DEFAULT,
                                     D3DFMT_UNKNOWN,
                                     D3DPOOL_DEFAULT,
                                     D3DX_DEFAULT,
                                     D3DX_DEFAULT,
                                     D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
                                     &d3dxImageInfo,
                                     NULL,
                                     &texture );
    
    	D3DXCreateSprite( sprite, &texture);
    	
    	kitty.x = 100;
    	kitty.y = 150;
    	kitty.width = 96;
    	kitty.height = 96;
    	kitty.movex = 8;
    	kitty.movey = 0;
    
    	return 1;
    }
    
    int Key_Down(int key);
    {
    	return (keys[key] & 0x80);
    }
    
    void Poll_Keyboard()
    {
    	dikeyboard->GetDeviceState(sizeof(keys), (LPVOID)&keys);
    }
    
    int Init_Direct3D(HWND hwnd)
    {
    	HRESULT result;
    
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
    	if (d3d == NULL)
    	{
    		MessageBox(hwnd, "Error Initializing D3D", "Error", MB_OK);
    		return 0;
    	}
    
    	D3DPRESENT_PARAMETERS d3dpp;
    	ZeroMemory(&d3dpp, sizeof(d3dpp));
    
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferCount = 1;
    	d3dpp.BackBufferWidth = 640;
    	d3dpp.BackBufferHeight = 480;
    	d3dpp.hDeviceWindow = hwnd;
    	d3dpp.EnableAutoDepthStencil = TRUE;
    	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    
    	d3d->CreateDevice(
    		D3DADAPTER_DEFAULT,
    		D3DDEVTYPE_HAL,
    		hwnd,
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    		&d3dpp,
    		&d3ddev);
    
    	if (d3ddev == NULL)
    	{
    		MessageBox(hwnd, "Failed to init d3ddev", "Error!!", MB_OK);
    		return 0;
    	}
    
    	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
    	d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
    	
    	//graphics initlaized... Now for the keyboard!
    
    	result = DirectInput8Create(
    		GetModuleHandle(NULL),
    		DIRECTINPUT_VERSION,
    		IID_IDirectInput8,
    		(void**)&dinput,
    		NULL);
    
    	if (result != DI_OK)
    		return 0;
    
    	result = dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
    	if (result != DI_OK)
    		return 0;
    
    	result = dikeyboard->SetDataFormat(&c_dfDIKeyboard);
    	if (result != DI_OK)
    		return 0;
    
    	result = dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    	if (result != DI_OK)
    		return 0;
    
    	result = dikeyboard->Acquire();
    	if (result != DI_OK)
    		return 0;
    
    	return 1;
    }
    
    
    
    LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_DESTROY:
    		if (d3ddev != NULL)
    			d3ddev->Release();
    
    		if (d3d != NULL)
    			d3d->Release();
    
    		if (dikeyboard != NULL)
    		{
    			dikeybaord->Unacquire();
    			dikeyboard->Release();
    			dikeyboard = NULL;
    		}
    
    		if (backbuffer != NULL)
    			backbuffer->Release();
    
    		if (sprite != NULL)
    			sprite->Release();
    
    		if (texture != NULL)
    			texture->Release();
    
    		/*if (dinput != NULL)
    			dinput->Release();       <------is this needed????*/
    	
    		//Game_End(hWnd);
    		
    		PostQuitMessage(0);
    	}
    	return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    	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 = "2D Sprite Test...";
    	wc.hIconSm = NULL;
    
    	return RegisterClassEx(&wc);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG msg;
    	HWND hWnd;
    
    	MyRegisterClass(hInstance);
    
    	hWnd = CreateWindow(
    			"2D Sprite Test...",
    			"2D Sprite Test...",
    			WS_OVERLAPPED,
    			CW_USEDEFAULT,
    			CW_USEDEFAULT,
    			640,
    			480,
    			NULL,
    			NULL,
    			hInstance,
    			NULL);
    
    	if (!hWnd)
    		return FALSE;
    
    	ShowWindow(hWnd, nCmdShow);
    	UpdateWindow(hWnd);
    
    	if (!Init_Direct3D(hWnd))
    		return 0;
    
    	if (!Game_Init(hWnd))
    	{
    		MessageBox(hWnd, "Error Initializing Game", "Error ..........!", MB_OK);
    		return 0;
    	}
    	
    	int done = 0;
    	while (!done)
    	{
    		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			if (msg.message == WM_QUIT)
    				done = 1;
    
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    		else
    			Game_Run(hWnd);
    	}
    	
    	return msg.wParam;
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Well I'm no directX programmer, but I'm willing to bet LP3DXSPRITE is supposed to be LPD3DXSPRITE.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    bloody heck.... yeah, that does it... now I have 11 other errors to tackle

    that's what I get for staring at code all day!

    Thanks!

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    Anyone know how I might resolve these errors?

    Thanks again!

    spritetest.obj : error LNK2001: unresolved external symbol _GUID_SysKeyboard
    spritetest.obj : error LNK2001: unresolved external symbol _DirectInput8Create@20
    spritetest.obj : error LNK2001: unresolved external symbol _IID_IDirectInput8A
    dinput.lib(dilib2.obj) : error LNK2001: unresolved external symbol _GUID_Key
    Debug/d3dspriter.exe : fatal error LNK1120: 4 unresolved externals

    (Relatively fixed :P code below):

    Code:
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <d3dx9core.h>
    #include <dinput.h>
    #include <windows.h>
    
    LPDIRECT3D9 d3d;
    LPDIRECT3DDEVICE9 d3ddev;
    LPDIRECT3DSURFACE9 backbuffer;
    
    
    //LPDIRECTSURFACE9 back;
    LPDIRECTINPUT8 dinput;
    LPDIRECTINPUTDEVICE8 dikeyboard;
    LPD3DXSPRITE sprite;
    LPDIRECT3DTEXTURE9 texture;
    char keys[256];
    
    int Init_Direct3D(HWND);
    int Key_Down(int key);
    void Poll_Keyboard();
    int Game_Init(HWND);
    void Game_Run(HWND);
    //void Game_End(HWND);
    
    typedef struct {
    	int x, y;
    	int width, height;
    	int movex, movey;
    } SPRITE;
    
    SPRITE kitty;
    
    void Game_Run(HWND hwnd)
    {
    	if (d3ddev == NULL)
    		return;
    
    	Poll_Keyboard();
    	if (Key_Down(DIK_LEFT))
    		kitty.x -= kitty.movex;
    	
    	if (Key_Down(DIK_RIGHT))
    		kitty.x -= kitty.movey;
    	
    	if (Key_Down(DIK_ESCAPE))
    	{
    		PostMessage(hwnd, WM_DESTROY, 0, 0);
    	}
    
    	if (d3ddev->BeginScene())
    	{
    		d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0,0,0));
    		D3DXVECTOR2 position((float)kitty.x, (float)kitty.y);
    		sprite->Draw(
    			texture,
    			NULL,
    			NULL,
    			NULL,
    			0,
    			&position,
    			D3DCOLOR_XRGB(255,255,255));
    		sprite->End();
    		d3ddev->EndScene();
    	}
    }
    
    int Game_Init(HWND hwnd)
    {
    	D3DXIMAGE_INFO d3dxImageInfo;
    
    	D3DXCreateTextureFromFileEx( d3ddev,
                                     "cat.bmp",
                                     96, // I had to set width manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
                                     96, // I had to set height manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
                                     1,   // Don't create mip-maps when you plan on using D3DXSPRITE. It throws off the pixel math for sprite animation.
                                     D3DPOOL_DEFAULT,
                                     D3DFMT_UNKNOWN,
                                     D3DPOOL_DEFAULT,
                                     D3DX_DEFAULT,
                                     D3DX_DEFAULT,
                                     D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
                                     &d3dxImageInfo,
                                     NULL,
                                     &texture );
    
    	D3DXCreateSprite(d3ddev, &sprite);
    	
    	kitty.x = 100;
    	kitty.y = 150;
    	kitty.width = 96;
    	kitty.height = 96;
    	kitty.movex = 8;
    	kitty.movey = 0;
    
    	return 1;
    }
    
    int Key_Down(int key)
    {
    	return (keys[key] & 0x80);
    }
    
    void Poll_Keyboard()
    {
    	dikeyboard->GetDeviceState(sizeof(keys), (LPVOID)&keys);
    }
    
    int Init_Direct3D(HWND hwnd)
    {
    	HRESULT result;
    
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
    	if (d3d == NULL)
    	{
    		MessageBox(hwnd, "Error Initializing D3D", "Error", MB_OK);
    		return 0;
    	}
    
    	D3DPRESENT_PARAMETERS d3dpp;
    	ZeroMemory(&d3dpp, sizeof(d3dpp));
    
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferCount = 1;
    	d3dpp.BackBufferWidth = 640;
    	d3dpp.BackBufferHeight = 480;
    	d3dpp.hDeviceWindow = hwnd;
    	d3dpp.EnableAutoDepthStencil = TRUE;
    	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    
    	d3d->CreateDevice(
    		D3DADAPTER_DEFAULT,
    		D3DDEVTYPE_HAL,
    		hwnd,
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    		&d3dpp,
    		&d3ddev);
    
    	if (d3ddev == NULL)
    	{
    		MessageBox(hwnd, "Failed to init d3ddev", "Error!!", MB_OK);
    		return 0;
    	}
    
    	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
    	d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
    	
    	//graphics initlaized... Now for the keyboard!
    
    	result = DirectInput8Create(
    		GetModuleHandle(NULL),
    		DIRECTINPUT_VERSION,
    		IID_IDirectInput8,
    		(void**)&dinput,
    		NULL);
    
    	if (result != DI_OK)
    		return 0;
    
    	result = dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
    	if (result != DI_OK)
    		return 0;
    
    	result = dikeyboard->SetDataFormat(&c_dfDIKeyboard);
    	if (result != DI_OK)
    		return 0;
    
    	result = dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    	if (result != DI_OK)
    		return 0;
    
    	result = dikeyboard->Acquire();
    	if (result != DI_OK)
    		return 0;
    
    	return 1;
    }
    
    
    
    LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_DESTROY:
    		if (d3ddev != NULL)
    			d3ddev->Release();
    
    		if (d3d != NULL)
    			d3d->Release();
    
    		if (dikeyboard != NULL)
    		{
    			dikeyboard->Unacquire();
    			dikeyboard->Release();
    			dikeyboard = NULL;
    		}
    
    		if (backbuffer != NULL)
    			backbuffer->Release();
    
    		if (sprite != NULL)
    			sprite->Release();
    
    		if (texture != NULL)
    			texture->Release();
    
    		/*if (dinput != NULL)
    			dinput->Release();       <------is this needed????*/
    	
    		//Game_End(hWnd);
    		
    		PostQuitMessage(0);
    	}
    	return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    	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 = "2D Sprite Test...";
    	wc.hIconSm = NULL;
    
    	return RegisterClassEx(&wc);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG msg;
    	HWND hWnd;
    
    	MyRegisterClass(hInstance);
    
    	hWnd = CreateWindow(
    			"2D Sprite Test...",
    			"2D Sprite Test...",
    			WS_OVERLAPPED,
    			CW_USEDEFAULT,
    			CW_USEDEFAULT,
    			640,
    			480,
    			NULL,
    			NULL,
    			hInstance,
    			NULL);
    
    	if (!hWnd)
    		return FALSE;
    
    	ShowWindow(hWnd, nCmdShow);
    	UpdateWindow(hWnd);
    
    	if (!Init_Direct3D(hWnd))
    		return 0;
    
    	if (!Game_Init(hWnd))
    	{
    		MessageBox(hWnd, "Error Initializing Game", "Error ..........!", MB_OK);
    		return 0;
    	}
    	
    	int done = 0;
    	while (!done)
    	{
    		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			if (msg.message == WM_QUIT)
    				done = 1;
    
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    		else
    			Game_Run(hWnd);
    	}
    	
    	return msg.wParam;
    }

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    It's not necessary to repost your entire code to fix those errors.

    spritetest.obj : error LNK2001: unresolved external symbol _GUID_SysKeyboard
    spritetest.obj : error LNK2001: unresolved external symbol _DirectInput8Create@20
    spritetest.obj : error LNK2001: unresolved external symbol _IID_IDirectInput8A
    dinput.lib(dilib2.obj) : error LNK2001: unresolved external symbol _GUID_Key
    First make sure you are linking with dxguid.lib.
    Second, make sure you are linking with dinput8.lib
    Third, make sure you define what version of DirectInput you want and then include the header file for directinput. If you don't, the include file basically has a catch in it so that it acts as if the entire file is excluded.

    Don't ask me why they did it this way because I think it's stupid too.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    bubba, bithub,

    Thanks a ton! Works now!

    You're right, Bubba-- that is a messed up way to go about implementing... But, it is MS

    -maxthecat

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange compile errors
    By csonx_p in forum C++ Programming
    Replies: 10
    Last Post: 07-28-2008, 12:41 PM
  2. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 06:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21