2 Replies - 9611 Views - Last Post: 10 February 2012 - 03:00 PM Rate Topic: -----

#1 prabh  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 381
  • Joined: 27-December 08

Linker Error LNK2019 MSDN can't help

Posted 10 February 2012 - 08:12 AM

I got this error
Error 1 error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "bool __cdecl InitDirect3D(void)" (?InitDirect3D@@YA_NXZ) H:\Users\Prabh\documents\visual studio 2010\Projects\RacingGame\RacingGame\main.obj RacingGame


main.cpp
#include <windows.h>
#include <d3dx9.h>
#include "Helper.h"
//globals
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
Direct3D d3d;
Device device;

// forward declarations
bool initWindow( HINSTANCE hInstance );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
bool InitDirect3D(void);
void render(void);
// This is winmain, the main entry point for Windows applications

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )
{
	// Initialize the window
	if ( !initWindow( hInstance ) )
	return false;
	if (!InitDirect3D())
		return false;
	// main message loop:
	MSG msg;
	ZeroMemory( &msg, sizeof( msg ) );
	while( msg.message!=WM_QUIT )
	{
	// Check the message queue
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else 
		{
			render();
		}
	}
	return (int) msg.wParam;
}

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",
		"DirectXExample",
		WS_OVERLAPPEDWINDOW,
		// the window class to use
		// the title bar text
		// the window style
		CW_USEDEFAULT, // the starting x coordinate
		CW_USEDEFAULT, // the starting y coordinate
		800, // the pixel width of the window
		600, // 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;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	// Check any available messages from the queue
	switch (message)
	{
		case WM_DESTROY:
		PostQuitMessage(0);
		break;
	}
	// Always return the message to the default window
	// procedure for further processing
	return DefWindowProc(hWnd, message, wParam, lParam);
}
//Initialize DirectX
bool InitDirect3D(void)
{
	d3d=NULL;
	device=NULL;
	if(NULL==(d3d=Direct3DCreate9(D3D_SDK_VERSION)))
	{
		return false;
	}

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp,sizeof(d3dpp));
	d3dpp.Windowed=TRUE;
	d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat=D3DFMT_UNKNOWN;
	d3dpp.BackBufferCount=1;
	d3dpp.BackBufferWidth=800;
	d3dpp.BackBufferHeight=600;
	d3dpp.EnableAutoDepthStencil=TRUE;
	d3dpp.AutoDepthStencilFormat=D3DFMT_D16;
	d3dpp.hDeviceWindow=wndHandle;
	if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,wndHandle,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&device)))
	{
		return false;
	}

	return true;

}

void render(void)
{
	if(device==NULL)
		return;
	device->Clear(0,NULL,D3DCLEAR_TARGET ,D3DCOLOR_XRGB(0,0,255),1.0,0);

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



and
Helper.h
#ifndef HELPER_H_INCLUDED
#define HELPER_H_INCLUDED
#include <string>
using namespace std;
typedef D3DXVECTOR3 Vector3;
typedef D3DXMATRIX Matrix;
typedef LPD3DXMESH Mesh;
typedef D3DLIGHT9 Light;
typedef D3DMATERIAL9 Material;
typedef D3DXCOLOR Color;
typedef LPDIRECT3DDEVICE9 Device;
typedef D3DXVECTOR2 Vector2;
typedef LPDIRECT3DTEXTURE9 Texture2D;
typedef LPD3DXFONT DxFont;
typedef LPDIRECT3D9 Direct3D;

#endif // HELPER_H_INCLUDED




Is This A Good Question/Topic? 0
  • +

Replies To: Linker Error LNK2019 MSDN can't help

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Linker Error LNK2019 MSDN can't help

Posted 10 February 2012 - 08:26 AM

You haven't properly linked the d3d9.lib library. There are a few ways of doing it. You need to add the .lib file to your solution, or you could do #pragma comment(lib, "d3d9.lib") in your header file.
Was This Post Helpful? 0
  • +
  • -

#3 Serapth  Icon User is offline

  • D.I.C Head

Reputation: 53
  • View blog
  • Posts: 153
  • Joined: 17-August 11

Re: Linker Error LNK2019 MSDN can't help

Posted 10 February 2012 - 03:00 PM

Not sure why you think MSDN can't help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1