DirectX 11 - Unexpected Token Identifier

Hi All,

Edit: I managed to figure out the error. Didn't check the d3d11.lib spelling, I used ll instead of 11...

I've been following a tutorial on getting a DirectX11 (www.directxtutorial.com) and when trying to execute the code I keep getting the error

syntax error: unexpected token 'identifier', expected 'type specifier' - combaseapi.h - Line 229
And that's building the project on Windows SDK Version 8.1

When running on Windows SDK 10.0.16299.0, I get the error 'cannot open file d3d11.lib'
Both versions are running on 32-bit, even running on 64-bit, I get the errors too.

There's no error in the code that's shown.

Source code below;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//Include Windows header files
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dcompiler.h>

//#include <d3dx11.h> - Deprecated
//#include <d3dx10.h>

//include the Direct3D library file
#pragma comment (lib, "d3dll.lib")
//#pragma comment (lib, "d3dx11.lib")
//#pragma comment (lib, "d3dx10.lib")

//global declarations
IDXGISwapChain *swapChain;
ID3D11Device *dev;
ID3D11DeviceContext *devcon;

//function prototypes
void InitD3D(HWND hWnd);
void CleanD3D(void);

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


//Entry point for any windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	//Handle for the window
	HWND hWnd;
	//struct holds information for the window class
	WNDCLASSEX wc;

	//Clear out the wndow class for use
	ZeroMemory(&wc, sizeof(WNDCLASSEX));

	//fill in the stuct with the needed information
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszClassName = L"WindowClass1";

	//register the window class
	RegisterClassEx(&wc);

	RECT wr = { 0,0,500,400 }; //Set the size, but not the position
	AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);

	//create the window and use the result as the handle
	hWnd = CreateWindowEx(NULL, L"WindowClass1", L"First Windows Program",
		WS_OVERLAPPEDWINDOW,
		300,
		300,
		wr.right - wr.left, //width of the window
		wr.bottom - wr.top, //Height of the window
		NULL,
		NULL,
		hInstance,
		NULL);

	//display the window on the screen
	ShowWindow(hWnd, nCmdShow);

	//Setup and initialize Direct3D
	InitD3D(hWnd);
	//enter the main loop:

	//this struct holds windows event messages
	MSG msg = { 0 };

	//wait for the next message in the queue - store the result in 'msg'
	while (TRUE)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			//Translate keystroke message into the right format
			TranslateMessage(&msg);

			//send the message to the WindowProc Function
			DispatchMessage(&msg);

			//check to see if it's time to quit
			if (msg.message == WM_QUIT)
				break;
		}
		else {
			// Run Game Code...
			// ...
			// ...
		}
	}
	//Clean up DirectX and COM
	CleanD3D();
	//return this part of the WM_QUIT message to windows
	return msg.wParam;
}

//this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	//sort through and find what code to run for the message given
	switch (message)
	{
		//this message is read when the window is closed
		case WM_DESTROY:
		{
			//Close the application entirely 
			PostQuitMessage(0);
			return 0;
		} break;
	}
	//Handle any messages the switch statement didn't
	return DefWindowProc(hWnd, message, wParam, lParam);
}

//This function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{
	//Create a struct to hold information about the swap chain
	DXGI_SWAP_CHAIN_DESC scd;

	//Clear out the struct for use
	ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

	//Fill the swap chain description struct
	scd.BufferCount = 1;
	scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	scd.OutputWindow = hWnd;
	scd.SampleDesc.Count = 4;
	scd.Windowed = TRUE;

	//create a device, device context and swap chain using the information in the 'scd' struct
	D3D11CreateDeviceAndSwapChain(NULL,
		D3D_DRIVER_TYPE_HARDWARE,
		NULL,
		NULL,
		NULL,
		NULL,
		D3D11_SDK_VERSION,
		&scd,
		&swapChain,
		&dev,
		NULL,
		&devcon);
}

//this is the function that cleans up Direct3D and COM
void CleanD3D(void)
{
	//close and release all exisiting COM objects
	swapChain->Release();
	dev->Release();
	devcon->Release();
}
Last edited on
Does this help?
https://developercommunity.visualstudio.com/content/problem/185399/error-c2760-in-combaseapih-with-windows-sdk-81-and.html

See the response highlighted in green.


As a workaround you can add this line before the includes:
 
struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error: 'identifier' was unexpected here" when using /permissive- 


Last edited on
Did you copy paste the code, otherwise how did you type ll instead of 11
and by the way that code is nasty, here is how we initialize d3d11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
HRESULT hr = S_OK;

UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

D3D_DRIVER_TYPE driverTypes[] =
{
    D3D_DRIVER_TYPE_HARDWARE,
    D3D_DRIVER_TYPE_WARP,
    D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );

D3D_FEARURE_LEVEL featureLevels[] =
{
    D3D_FEATURE_LEVEL_11_0,
    D3D_FEATURE_LEVEL_10_1,
    D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );

DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
sd.OutputWindow = g_hWnd;
sd.Windowed = TRUE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = 0;

D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_NULL;
D3D_FEATURE_LEVEL featureLevel;

for ( UINT i = 0; i < numDriverTypes; i++ )
{
    driverType = driverTypes[ i ];
    hr = D3D11CreateDeviceAndSwapChain( nullptr, driverType, nullptr, createDeviceFlags,
                                                                featureLevels, numFeatureLevels, 
                                                                D3D11_SDK_VERSION, &sd, &pSwapChain,
                                                                &pd3dDevice, &featureLevel, 
                                                                &pImmediateContext  );
    if ( SUCCEEDED( hr ) )
        break;
}
if ( FAILED( hr ) )
        // handle the error.
Last edited on
Topic archived. No new replies allowed.