7 Replies - 2529 Views - Last Post: 19 March 2011 - 02:58 PM Rate Topic: -----

#1 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Can't resolve symbols (DirectX)

Posted 19 March 2011 - 12:49 PM

// include basic window header and Direct3D header file
#include <Windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <d3dx9.h>

// define screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

// include the Direct3D libs
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

// global declarations
LPDIRECT3D9 d3d; // pointer to Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // pointer to device class
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // pointer to the vertex buffer

// function prototypes
void initD3D(HWND hWnd); // sets up and inits D3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes D3D and releases memory
void init_graphics(void); // 3D declarations

struct CUSTOMVERTEX {FLOAT x, y, z; DWORD color;};
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

// the entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
	HWND hWnd;
	WNDCLASSEX wc;

	ZeroMemory(&wc, sizeof(WNDCLASSEX));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.lpszClassName = "WindowClass";

	RegisterClassEx(&wc);

	hWnd = CreateWindowEx(NULL,
						  "Window Class",
						  "Out Direct3D Program",
						  WS_OVERLAPPEDWINDOW,
						  0, 0,
						  SCREEN_WIDTH, SCREEN_HEIGHT,
						  NULL, NULL,
						  hInstance, NULL);

	ShowWindow(hWnd, nCmdShow);

	// set up and init D3D
	initD3D(hWnd);

	// enter the main loop:
	MSG msg;

	while (TRUE)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		if (msg.message == WM_QUIT)
			break;

		render_frame();
	}

	// clean up DirectX and COM
	cleanD3D();

	return msg.wParam;

}

// main message hander for program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_DESTROY:
			{
				PostQuitMessage(0);
				return 0;
			} break;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

// this prepares and initz D3D
void initD3D(HWND hWnd)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp, sizeof(d3dpp));

	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = SCREEN_WIDTH;
	d3dpp.BackBufferHeight = SCREEN_HEIGHT;

	// create a device class using this info
	d3d->CreateDevice(D3DADAPTER_DEFAULT,
					  D3DDEVTYPE_HAL,
					  hWnd,
					  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
					  &d3dpp,
					  &d3ddev);

	init_graphics(); // can func to init triangle

	d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
}

// render single frame
void render_frame(void)
{
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	d3ddev->BeginScene();

	// select which vertex format to use
	d3ddev->SetFVF(CUSTOMFVF);

	// SET UP THE PIPELINE

	D3DXMATRIX matRotateY; // a matrix to store the rotation info
	
	// an ever increasing float value
	static float index = 0.0f; 
	index += 0.05f;

	// build a matrix to rotate the model based on the increasing float value
	D3DXMatrixRotationY(&matRotateY, index);

	// tell D3D about our matrix
	d3ddev->SetTransform(D3DTS_WORLD, &matRotateY);

	D3DXMATRIX matView; // the view transform matrix

	D3DXMatrixLookAtLH(&matView,
					   &D3DXVECTOR3(0.0f, 0.0f, 10.0f), // the cam position
					   &D3DXVECTOR3(0.0f, 0.0f, 0.0), // the look-at position
					   &D3DXVECTOR3(0.0f, 1.0f, 0.0)); // the loop up direction

	d3ddev->SetTransform(D3DTS_VIEW, &matView); // set the view transform to matView

	D3DXMATRIX matProjection; // the projection matrix

	D3DXMatrixPerspectiveFovLH(&matProjection,
		                       D3DXToRadian(45), // the horizontal field view
							   (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
							   1.0f, // the near view-plane
							   100.0f); // the far view-plane

	d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection); // set the projection

	// select the vertex buffer to display
	d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

	// copy the vertex buffer to the back buffer
	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	d3ddev->EndScene();

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

// clean up D3D and COM
void cleanD3D(void)
{
	v_buffer->Release(); // close and release he vertex buffer
	d3ddev->Release(); // close and release 3D device
	d3d->Release(); // close and rlease D3D
}

// this puts the 3D models into the video RAM
void init_graphics(void)
{
	// create the vertices using the CUSTOMVERTEX struct
	CUSTOMVERTEX vertices[] = 
	{
		{3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
		{0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
		{-3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
	};

	// create a vertex buffer interface called v_buffer
	d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
							   0,
							   CUSTOMFVF,
							   D3DPOOL_MANAGED,
							   &v_buffer,
							   NULL);

	VOID *pVoid; // a void pointer

	// lock v_buffer and load the vertices into it
	v_buffer->Lock(0, 0, (void **)&pVoid, 0);
	memcpy(pVoid, vertices, sizeof(vertices));
	v_buffer->Unlock();
}




I'm following along with directxtutorial.com, reading it all, absorbing it, and practicing.
This code, when compiled gives these errors:


1>------ Build started: Project: moving triangle, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "void __cdecl initD3D(struct HWND__ *)" (?initD3D@@YAXPAUHWND__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
1>c:\users\andrew\documents\visual studio 2010\Projects\moving triangle\Debug\moving triangle.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I have no idea what they were talking about. I checked all the mentioned functions, and they seem fine compared to the one on the site. I have linked the project to the June 2010 SDK headers and libs. What's wrong here?

This post has been edited by heyoman1: 19 March 2011 - 12:52 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Can't resolve symbols (DirectX)

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,194
  • Joined: 14-February 08

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 01:15 PM

You need to add the libraries to the additional dependencies in your project properties.
Was This Post Helpful? 1
  • +
  • -

#3 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 01:32 PM

I did.
Posted Image
Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

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

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 01:48 PM

Well, your paths aren't set up correctly between where your IDE is searching and where the libraries actually reside. You need to check this.
Was This Post Helpful? 0
  • +
  • -

#5 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 01:53 PM

For some reason, when I change the lib file was from :
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64
to
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86
it compiled, but no window shows up.
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

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

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 02:45 PM

View Postheyoman1, on 19 March 2011 - 08:53 PM, said:

For some reason, when I change the lib file was from :
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64
to
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86
it compiled, but no window shows up.

That's because you switched from using the 64-bit to 32-bit libs. Sounds about right!

Now you need to look at your window init code. :)

View Postheyoman1, on 19 March 2011 - 08:32 PM, said:

I did.
Posted Image
Posted Image

I was viewing these images from my iphone before so couldn't see what the path strings were. They look odd. Have you changed them?

This post has been edited by ButchDean: 19 March 2011 - 02:43 PM

Was This Post Helpful? 1
  • +
  • -

#7 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 02:56 PM

View PostButchDean, on 19 March 2011 - 05:45 PM, said:

I was viewing these images from my iphone before so couldn't see what the path strings were. They look odd. Have you changed them?

In the first image, the path that was there was in my previous post. And in the second image, there was a list of .libs (or .dll's), and when I went to enter those 2 libs, the others were somehow removed from the list.
Was This Post Helpful? 0
  • +
  • -

#8 anonymous26  Icon User is offline

  • D.I.C Lover

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

Re: Can't resolve symbols (DirectX)

Posted 19 March 2011 - 02:58 PM

View Postheyoman1, on 19 March 2011 - 09:56 PM, said:

View PostButchDean, on 19 March 2011 - 05:45 PM, said:

I was viewing these images from my iphone before so couldn't see what the path strings were. They look odd. Have you changed them?

In the first image, the path that was there was in my previous post. And in the second image, there was a list of .libs (or .dll's), and when I went to enter those 2 libs, the others were somehow removed from the list.

Okay. Well, if path problems persist you can uninstall and reinstall the DirectX SDK without it affecting your project.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1