Problem with initalization Direct

Category: windows metro apps games

Question

Yerrp on Wed, 12 Nov 2014 12:59:10


// D3DProject.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "D3DProject.h"
#include "d3dApp.h"


#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name
class InitDirect3DApp : public D3DApp
{
public:
	InitDirect3DApp(HINSTANCE hInstance);
	~InitDirect3DApp();

	bool Init();
	void OnResize();
	void UpdateScene(float dt);
	void DrawScene();
};
// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
	PSTR cmdLine, int showCmd)
{


 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_D3DPROJECT, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, showCmd))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_D3DPROJECT));
#if defined(DEBUG) | defined(_DEBUG)
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	InitDirect3DApp theApp(hInstance);
	
	if (!theApp.Init())
		return 0;
	return theApp.Run();
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_D3DPROJECT));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_D3DPROJECT);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}
InitDirect3DApp::InitDirect3DApp(HINSTANCE hInstance)
	: D3DApp(hInstance)
{
}

InitDirect3DApp::~InitDirect3DApp()
{
}

bool InitDirect3DApp::Init()
{
	if (!D3DApp::Init())
		return false;

	return true;
}

void InitDirect3DApp::OnResize()
{
	D3DApp::OnResize();
}

void InitDirect3DApp::UpdateScene(float dt)
{

}

void InitDirect3DApp::DrawScene()
{
	assert(md3dImmediateContext);
	assert(mSwapChain);

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Blue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

	HR(mSwapChain->Present(0, 0));
}

When I'm building solution, have 7 errors, I was trying so many things and it still not working ;/

Errors:

Error 1 error LNK2019: unresolved external symbol _DXTraceW@20 referenced in function "public: virtual void __thiscall InitDirect3DApp::DrawScene(void)" (?DrawScene@InitDirect3DApp@@UAEXXZ) C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 6 error LNK2019: unresolved external symbol "public: virtual void __thiscall D3DApp::OnResize(void)" (?OnResize@D3DApp@@UAEXXZ) referenced in function "public: virtual void __thiscall InitDirect3DApp::OnResize(void)" (?OnResize@InitDirect3DApp@@UAEXXZ) C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 5 error LNK2019: unresolved external symbol "public: virtual bool __thiscall D3DApp::Init(void)" (?Init@D3DApp@@UAE_NXZ) referenced in function "public: virtual bool __thiscall InitDirect3DApp::Init(void)" (?Init@InitDirect3DApp@@UAE_NXZ) C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 3 error LNK2019: unresolved external symbol "public: virtual __thiscall D3DApp::~D3DApp(void)" (??1D3DApp@@UAE@XZ) referenced in function "public: virtual __thiscall InitDirect3DApp::~InitDirect3DApp(void)" (??1InitDirect3DApp@@UAE@XZ) C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 4 error LNK2019: unresolved external symbol "public: int __thiscall D3DApp::Run(void)" (?Run@D3DApp@@QAEHXZ) referenced in function _WinMain@16 C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 2 error LNK2019: unresolved external symbol "public: __thiscall D3DApp::D3DApp(struct HINSTANCE__ *)" (??0D3DApp@@QAE@PAUHINSTANCE__@@@Z) referenced in function "public: __thiscall InitDirect3DApp::InitDirect3DApp(struct HINSTANCE__ *)" (??0InitDirect3DApp@@QAE@PAUHINSTANCE__@@@Z) C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 7 error LNK2001: unresolved external symbol "public: virtual long __thiscall D3DApp::MsgProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MsgProc@D3DApp@@UAEJPAUHWND__@@IIJ@Z) C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\D3DProject\D3DProject.obj D3DProject
Error 8 error LNK1120: 7 unresolved externals C:\Users\Maciej\documents\visual studio 2013\Projects\D3DProject\Debug\D3DProject.exe D3DProject


Replies

James Dailey - MSFT on Wed, 12 Nov 2014 23:36:08


Hello,

Where do you define D3DApp::OnResize? As the errors indicate you are missing function definitions for the D3DApp class in the code that you posted.

-James

Chuck Walbourn - MSFT on Thu, 13 Nov 2014 21:37:18


Where are you getting a reference to DXTrace from? What are you using in your stdafx.h?