Hi again!
i currentley working with dx10 (i had to work in c# and xna along with maya for the last year) for a uni project and wanted to have the 3d heavy lifting done in a seprate class/cpp file (with header file so that it would work), i have now written the code but get the following error:
Error 3 error LNK2019: unresolved external symbol _D3D10CreateDeviceAndSwapChain@32 referenced in function "public: bool __thiscall dx10Manager::initialize(struct HWND__ * *)" (?initialize@dx10Manager@@QAE_NPAPAUHWND__@@@Z) dx10Manager.obj dx10Test02
header
dx class
window code
i think its something to do with the way that code is called or how the main win calls the code all of the soure code compiles ok but i think i havent done something in the visual studio envroment (using VS2008), i stated with an empty project and added header then code
thanks for your help!!!
i currentley working with dx10 (i had to work in c# and xna along with maya for the last year) for a uni project and wanted to have the 3d heavy lifting done in a seprate class/cpp file (with header file so that it would work), i have now written the code but get the following error:
Error 3 error LNK2019: unresolved external symbol _D3D10CreateDeviceAndSwapChain@32 referenced in function "public: bool __thiscall dx10Manager::initialize(struct HWND__ * *)" (?initialize@dx10Manager@@QAE_NPAPAUHWND__@@@Z) dx10Manager.obj dx10Test02
header
#ifndef DXMANAGER
#define DXMANAGER
#include <windows.h>
#include <d3d10.h>
#include <d3dx10.h>
class dx10Manager
{
/****************************************************************************
* List of the Members used in the dx10manager
****************************************************************************/
private:
//Window handle
HWND* hWnd;
//device vars
ID3D10Device* pD3DDevice;
IDXGISwapChain* pSwapChain;
ID3D10RenderTargetView* pRenderTargetView;
D3D10_VIEWPORT viewPort;
//Projection and view matrices
D3DXMATRIX viewMatrix;
D3DXMATRIX projectionMatrix;
/*****************************************************************************
* Methods
*****************************************************************************/
public:
//Constructor and destructor
dx10Manager();
~dx10Manager();
//initialize directX device
bool initialize(HWND*);
//renderScene
void renderScene();
private:
//fatal error handler
bool fatalError(LPCSTR msg);
};
#endif
#define DXMANAGER
#include <windows.h>
#include <d3d10.h>
#include <d3dx10.h>
class dx10Manager
{
/****************************************************************************
* List of the Members used in the dx10manager
****************************************************************************/
private:
//Window handle
HWND* hWnd;
//device vars
ID3D10Device* pD3DDevice;
IDXGISwapChain* pSwapChain;
ID3D10RenderTargetView* pRenderTargetView;
D3D10_VIEWPORT viewPort;
//Projection and view matrices
D3DXMATRIX viewMatrix;
D3DXMATRIX projectionMatrix;
/*****************************************************************************
* Methods
*****************************************************************************/
public:
//Constructor and destructor
dx10Manager();
~dx10Manager();
//initialize directX device
bool initialize(HWND*);
//renderScene
void renderScene();
private:
//fatal error handler
bool fatalError(LPCSTR msg);
};
#endif
dx class
#include "dx10Manager.h"
/****************************************************************************
* Construtor
****************************************************************************/
dx10Manager::dx10Manager(): pD3DDevice(NULL),
pSwapChain(NULL),
pRenderTargetView(NULL)
{
}
/****************************************************************************
* Destructor
****************************************************************************/
dx10Manager::~dx10Manager()
{
if(pRenderTargetView) pRenderTargetView->Release();
if(pSwapChain) pSwapChain->Release();
if(pD3DDevice) pD3DDevice->Release();
}
/****************************************************************************
* Initializes Direct3D Device
****************************************************************************/
bool dx10Manager::initialize(HWND*hW)
{
//window handle
hWnd = hW;
//get window dimensions
RECT rc;
GetClientRect(*hWnd, &rc);
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
//Setup DX swap chain
//-------------------
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
//set buffer dimensions and format
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;;
//set refresh rate
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
//sampling settings
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SampleDesc.Count = 1;
//OUTPUT WINDOW handle
swapChainDesc.OutputWindow = *hWnd;
swapChainDesc.Windowed = true;
//Create the D£D device
//---------------------
if (FAILED(D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &swapChainDesc, &pSwapChain, &pD3DDevice))) return fatalError("D3D device creation failed");
//Create render target view
//-------------------------
//try to get the back buffer
ID3D10Texture2D* pBackBuffer;
if (FAILED(pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer))) return fatalError("Could not get back buffer");
//try to create render target view
if (FAILED(pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView))) return fatalError("Could not create render target view");
//release the back buffer
pBackBuffer->Release();
//set the render target
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
//Create viewport
//---------------
//create viewport structure
viewPort.Width = width;
viewPort.Height = height;
viewPort.MinDepth = 0.0f;
viewPort.MaxDepth = 1.0f;
viewPort.TopLeftX = 0;
viewPort.TopLeftY = 0;
//set the viewport
pD3DDevice->RSSetViewports(1, &viewPort);
// Set up the view matrix
//-----------------------
D3DXMatrixLookAtLH(&viewMatrix, new D3DXVECTOR3(0.0f, 0.0f, -5.0f),
new D3DXVECTOR3(0.0f, 0.0f, 1.0f),
new D3DXVECTOR3(0.0f, 1.0f, 0.0f));
//Set up projection matrix
//------------------------
D3DXMatrixPerspectiveFovLH(&projectionMatrix, (float)D3DX_PI * 0.5f, (float)width/(float)height, 0.1f, 100.0f);
//everything completed successfully
return true;
}
/****************************************************************************
* Scene Renderer
****************************************************************************/
void dx10Manager::renderScene()
{
//clear scene
pD3DDevice->ClearRenderTargetView( pRenderTargetView, D3DXCOLOR(0,0,0,0) );
//SCENE RENDERING GOES HERE!!!
//flip buffers
pSwapChain->Present(0,0);
}
/****************************************************************************
* Fatal Error Handler
****************************************************************************/
bool dx10Manager::fatalError(LPCSTR msg)
{
MessageBox(*hWnd, msg, "Fatal Error!", MB_ICONERROR);
return false;
}
/****************************************************************************
* Construtor
****************************************************************************/
dx10Manager::dx10Manager(): pD3DDevice(NULL),
pSwapChain(NULL),
pRenderTargetView(NULL)
{
}
/****************************************************************************
* Destructor
****************************************************************************/
dx10Manager::~dx10Manager()
{
if(pRenderTargetView) pRenderTargetView->Release();
if(pSwapChain) pSwapChain->Release();
if(pD3DDevice) pD3DDevice->Release();
}
/****************************************************************************
* Initializes Direct3D Device
****************************************************************************/
bool dx10Manager::initialize(HWND*hW)
{
//window handle
hWnd = hW;
//get window dimensions
RECT rc;
GetClientRect(*hWnd, &rc);
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
//Setup DX swap chain
//-------------------
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
//set buffer dimensions and format
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;;
//set refresh rate
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
//sampling settings
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SampleDesc.Count = 1;
//OUTPUT WINDOW handle
swapChainDesc.OutputWindow = *hWnd;
swapChainDesc.Windowed = true;
//Create the D£D device
//---------------------
if (FAILED(D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &swapChainDesc, &pSwapChain, &pD3DDevice))) return fatalError("D3D device creation failed");
//Create render target view
//-------------------------
//try to get the back buffer
ID3D10Texture2D* pBackBuffer;
if (FAILED(pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer))) return fatalError("Could not get back buffer");
//try to create render target view
if (FAILED(pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView))) return fatalError("Could not create render target view");
//release the back buffer
pBackBuffer->Release();
//set the render target
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
//Create viewport
//---------------
//create viewport structure
viewPort.Width = width;
viewPort.Height = height;
viewPort.MinDepth = 0.0f;
viewPort.MaxDepth = 1.0f;
viewPort.TopLeftX = 0;
viewPort.TopLeftY = 0;
//set the viewport
pD3DDevice->RSSetViewports(1, &viewPort);
// Set up the view matrix
//-----------------------
D3DXMatrixLookAtLH(&viewMatrix, new D3DXVECTOR3(0.0f, 0.0f, -5.0f),
new D3DXVECTOR3(0.0f, 0.0f, 1.0f),
new D3DXVECTOR3(0.0f, 1.0f, 0.0f));
//Set up projection matrix
//------------------------
D3DXMatrixPerspectiveFovLH(&projectionMatrix, (float)D3DX_PI * 0.5f, (float)width/(float)height, 0.1f, 100.0f);
//everything completed successfully
return true;
}
/****************************************************************************
* Scene Renderer
****************************************************************************/
void dx10Manager::renderScene()
{
//clear scene
pD3DDevice->ClearRenderTargetView( pRenderTargetView, D3DXCOLOR(0,0,0,0) );
//SCENE RENDERING GOES HERE!!!
//flip buffers
pSwapChain->Present(0,0);
}
/****************************************************************************
* Fatal Error Handler
****************************************************************************/
bool dx10Manager::fatalError(LPCSTR msg)
{
MessageBox(*hWnd, msg, "Fatal Error!", MB_ICONERROR);
return false;
}
window code
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "dx10Manager.h"
/*******************************************************************
* Global Variables
*******************************************************************/
HWND hWnd; //window handle
int windowWidth = 800;
int windowHeight = 600;
//directX manager
dx10Manager dx;
/*******************************************************************
* Main Window Procedure - handles application events
*******************************************************************/
LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// Allow the user to press the escape key to end the application
case WM_KEYDOWN : switch(wParam)
{
// Check if the user hit the escape key
case VK_ESCAPE : PostQuitMessage(0);
break;
}
break;
// The user hit the close button, close the application
case WM_DESTROY : PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/*******************************************************************
* Initialize Main Window
********************************************************************/
bool initWindow(HWND &hWnd, HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)wndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DX10Test2");
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
//Resize the window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE);
//create the window from the class above
//disable resizing and correct for extra width and height
hWnd = CreateWindow( "DX10Test2",
"DX10 tests and lessons 2 - Initializing the Device using a manager class",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
//window handle not created
if (!hWnd) return false;
//if window creation was successful
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return true;
}
/*******************************************************************
* WinMain
*******************************************************************/
int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
// Set up the application window
if ( !initWindow(hWnd, hInstance, windowWidth, windowHeight)) return 0;
//set up directx manager
if ( !dx.initialize(&hWnd) ) return 0;
// Main message loop
MSG msg = {0};
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
dx.renderScene();
}
return (int) msg.wParam;
}
#include <tchar.h>
#include <stdio.h>
#include "dx10Manager.h"
/*******************************************************************
* Global Variables
*******************************************************************/
HWND hWnd; //window handle
int windowWidth = 800;
int windowHeight = 600;
//directX manager
dx10Manager dx;
/*******************************************************************
* Main Window Procedure - handles application events
*******************************************************************/
LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// Allow the user to press the escape key to end the application
case WM_KEYDOWN : switch(wParam)
{
// Check if the user hit the escape key
case VK_ESCAPE : PostQuitMessage(0);
break;
}
break;
// The user hit the close button, close the application
case WM_DESTROY : PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/*******************************************************************
* Initialize Main Window
********************************************************************/
bool initWindow(HWND &hWnd, HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)wndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DX10Test2");
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
//Resize the window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE);
//create the window from the class above
//disable resizing and correct for extra width and height
hWnd = CreateWindow( "DX10Test2",
"DX10 tests and lessons 2 - Initializing the Device using a manager class",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
//window handle not created
if (!hWnd) return false;
//if window creation was successful
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return true;
}
/*******************************************************************
* WinMain
*******************************************************************/
int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
// Set up the application window
if ( !initWindow(hWnd, hInstance, windowWidth, windowHeight)) return 0;
//set up directx manager
if ( !dx.initialize(&hWnd) ) return 0;
// Main message loop
MSG msg = {0};
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
dx.renderScene();
}
return (int) msg.wParam;
}
i think its something to do with the way that code is called or how the main win calls the code all of the soure code compiles ok but i think i havent done something in the visual studio envroment (using VS2008), i stated with an empty project and added header then code
thanks for your help!!!
Last edited by a moderator: