Error Help

Started by
6 comments, last by Silamoth 10 years ago

I am learning DirectX from a book. I am getting an error on the code. Here is all mof


#include <Windows.h>
#include <tchar.h>
#include <DXGI.h>

HINSTANCE hInst;
HWND wndHandle;

int width = 640;
int height = 480;

bool InitWindow (HINSTANCE hInstance, int width, int height);
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
									LPTSTR lpCmdLine, int nCMDShow)
{

	if (!InitWindow(hInstance, width, height))
	{

		return false;

	}

	MSG msg = {0};
	while (WM_QUIT != msg.message)
	{

		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
		{

			TranslateMessage(&msg);
			DispatchMessage(&msg);

		}

	}

	return (int) msg.wParam;
}

	bool InitWindow (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("DirectXExample");
	wcex.hIconSm = 0;
	RegisterClassEx(&wcex);

	RECT rect = {0, 0, width, height};
	AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);

	wndHandle = CreateWindow(TEXT("DirectXExample"),
		TEXT("DirectXExample"),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		rect.right - rect.left,
		rect.bottom - rect.top,
		NULL,
		NULL,
		hInstance,
		NULL);

	if (!wndHandle)
	{

		return false;

	}

	ShowWindow(wndHandle, SW_SHOW);
	UpdateWindow(wndHandle);

	return true;

}

	LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{

		switch (message)
		{

		case WM_KEYDOWN:
			switch (wParam)
			{

			case VK_ESCAPE:
				PostQuitMessage(0);
			break;

			}

			break;
			
		case WM_DESTROY:
			PostQuitMessage(0);
		break;

		}

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

	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	swapChainDesc.BufferDesc.Width = 640;
	swapChainDesc.BufferDesc.Height = 480;
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount = 1;
	swapChainDesc.OutputWindow = hWnd;
	swapChainDesc.Windowed = TRUE;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_NONPREROTATED;

	 HRESULT D3D10CreateDeviceAndSwapChain ( NULL,
		D3D10_DRIVER_TYPE_REFERENCE,
		NULL,
		0,
		D3D10_SDK_VERSION,
		&swapChainDesc,
		&swapChain,
		&pD3DDevice);

	}

I get an error on the "," after the NULL in the block of code at the end. It says "Expected a ')'". Here are my build errors:


Error	1	error C2065: 'D3D10_DRIVER_TYPE_REFERENCE' : undeclared identifier	c:\users\michael\documents\visual studio 2012\projects\directx\winmain.cpp	134	1	DirectX
Error	2	error C2065: 'D3D10_SDK_VERSION' : undeclared identifier	c:\users\michael\documents\visual studio 2012\projects\directx\winmain.cpp	137	1	DirectX
Error	3	error C2065: 'swapChain' : undeclared identifier	c:\users\michael\documents\visual studio 2012\projects\directx\winmain.cpp	139	1	DirectX
Error	4	error C2065: 'pD3DDevice' : undeclared identifier	c:\users\michael\documents\visual studio 2012\projects\directx\winmain.cpp	140	1	DirectX
Error	5	error C2078: too many initializers	c:\users\michael\documents\visual studio 2012\projects\directx\winmain.cpp	140	1	DirectX
	6	IntelliSense: expected a ')'	c:\Users\Michael\Documents\Visual Studio 2012\Projects\DirectX\winmain.cpp	133	47	DirectX

Please help.

Advertisement

You have to include the appropriate D3D10 header files. E.g., D3D10.h, etc.

If you're using Visual Studio, open up the help docs and search for the "undeclared identifier" when that identifier is other than one of your own variables. The docs for that constant or function will list the headers and libraries you have to include in your project. E.g., open up help and search the index for D3D10_DRIVER_TYPE_REFERENCE. That should take you to the enumeration description. Near the bottom of the page you'll see a Requirements table. It lists d3d10misc.h. However, start with #include <d3d10.h> as that header will likely include most other info that you'll need for starters.

If the book you're using is worth anything, it should discuss headers and libraries and describe what's needed in each example or project.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

The book I am using does not talk about headers and libraries. But I was able to fix 2 errors by including your suggested header. I was able to fix another by turning off Intellisense errors. Although my book does not talk about headers and libraries, it does come with a CD containing examples. I found that I should be doing something like this


 HRESULT hr = D3D10CreateDeviceAndSwapChain ( NULL,
		D3D10_DRIVER_TYPE_REFERENCE,
		NULL,
		0,
		D3D10_SDK_VERSION,
		&swapChainDesc,
		&pSwapChain,
		&pD3DDevice);

instead of


HRESULT D3D10CreateDeviceAndSwapChain ( NULL,
		D3D10_DRIVER_TYPE_REFERENCE,
		NULL,
		0,
		D3D10_SDK_VERSION,
		&swapChainDesc,
		&swapChain,
		&pD3DDevice);
 

Thanks for your help.

Now I have another problem. I added this bit of code:


ID3D10Texture2D *pBackBuffer;
	 HRESULT hr2 = pSwapChain->GetBuffer(0,__uuidof(ID3D10Texture2D), (LPVOID*)
	 &pBackBuffer);
	 if (hr2 != S_OK)
	 {

		 return false;

	 }

	 hr2 = pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL,
	&pRenderTargetView);

	 pBackBuffer->Release();

	 if (hr2 != S_OK)
	 {

		 return false;

	 }

	 pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);

	 D3D10_VIEWPORT viewPort;
	 viewPort.Width = width;
	 viewPort.Height = height;
	 viewPort.MinDepth = 0.0f;
	 viewPort.MaxDepth = 1.0f;
	 viewPort.TopLeftX = 0;
	 viewPort.TopLeftY = 0;

	 pD3DDevice->RSSetViewports(1, &viewPort);

	 pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));

My D3DXCOLOR gets an error saying "D3DXCOLOR is undefined." My build errors are as follows:


Error	1	error C3861: 'D3DXCOLOR': identifier not found	c:\users\michael\documents\visual studio 2012\projects\directx\winmain.cpp	184	1	DirectX
	2	IntelliSense: identifier "D3DXCOLOR" is undefined	c:\Users\Michael\Documents\Visual Studio 2012\Projects\DirectX\winmain.cpp	184	56	DirectX

What now?

Did you look in the documentation as suggested?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Yes, here. I found an outdated header for DX9. Do you know why it isn't working?


I found an outdated header for DX9

Why do you say it's outdated? What error did you get when you included it? If you don't want to include the header, use something else to define the clear color. Did you look at the docs for ClearRenderTargetView? Again (and again), the documentation is there to help you.


Do you know why it isn't working?

Why what isn't working?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I did some even further research and found out that D3DXCOLOR is no longer supported. Why, I am not sure. I was able to use a float instead and it now works.

This topic is closed to new replies.

Advertisement