[C++] Linking libraries and outdated VS-VC++

Started by
6 comments, last by Rudra 12 years, 3 months ago
Okay so here is my dilemma. I have purchased "Beginning game Programming 3rd ed" by Jonathan S. Harbour. The book uses the Xp OS and DX9, and VC++. Im using a Win 7 and DX11 with VC++ Express edition.

I discovered that VC++ and DX11 are not compatible, but, my VS2010 and DX11 are. On chapter 3 of the book i wrote out the code, linked the libraries and include file of DX11 to VS2010. However, im getting an ungodly amount of errors all related to DX11. On top of that im also getting "System can not find file specified". Now is there a possibility that the DX11 function calls are different from DX9? If so where can i find the related code in DX11? And two, how can i fix the "System can not find file specified"?

I will include my code if there is possibility of it being a syntax issue.

EDIT:: I would like to note that when i installed DX11 i received a S1023 error.


The following is my code::

#include<d3d11.h>

#include<windows.h>
#include<time.h>
#include<iostream>
using namespace std;

//#pragma comment(lib,"d3d11.lib")
//#pragma comment(lib, "d3dx11.lib")

const string APPTITLE = "Direct3D_Windowed";
const int SCREENW = 1024;
const int SCREENH = 768;

LPDIRECT3D11 d3d = NULL;
LPDIRECT3DDEVICE11 d3ddev = NULL;


bool gameover = false;

#define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)&0x8000)? 1 : 0)

bool Game_Init(HWND window)
{

MessageBox(window, "Game_Init", "BREAKPOINT", 0);

d3d = Direct3DCreate11(D3D_SDK_VERSION);
if(d3d = NULL)
{
MessageBox(window, "Error initializing Direct3D", "Error", MB_OK);
return 0;
}

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREENW;
d3dpp.BackBufferHeight = SCREENH;
d3dpp.hDeviceWindow = window;

d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);

if(d3ddev = NULL)
{
MessageBox(window, "Error creating Direct3D device", "Error", MB_OK);
return 0;
}
return true;
}

void Game_Run(HWND hwnd)
{
if(!d3ddev)return;

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f, 0);

if(d3ddev->BeginScene())
{
//do something

d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);

}

if(KEY_DOWN(VK_ESCAPE))
PostMessage(hwnd, WM_DESTROY, 0,0);

}

void Game_End(HWND hwnd)
{

MessageBox(hwnd, "Program is about to end", "Game_End", MB_OK);

if(d3ddev) d3ddev->Release();
if(d3d)d3d->Release();
}

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
gameover = true;
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc =(WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE.c_str();
wc.hIconSm = NULL;
RegisterClassEx(&wc);

HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREENW, SCREENH, NULL, NULL, hInstance, NULL);

if(window == 0) return 0;

ShowWindow(window, nCmdShow);
UpdateWindow(window);

if(!Game_Init(window)) return 0;

MSG message;
while(!gameover)
{
if(PeekMessage(&message, NULL, 0,0, PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessage(&message);
}

Game_Run(window);
}
Game_End(window);

return message.wParam;

}[/quote]




The following errors are reported::



(15) : error C2146: syntax error : missing ';' before identifier 'd3d'
(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(16) : error C2146: syntax error : missing ';' before identifier 'd3ddev'
(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(28) : error C2065: 'D3D_SDK_VERSION' : undeclared identifier
(28) : error C3861: 'Direct3DCreate11': identifier not found
(35) : error C2065: 'D3DPRESENT_PARAMETERS' : undeclared identifier
(35) : error C2146: syntax error : missing ';' before identifier 'd3dpp'
(35) : error C2065: 'd3dpp' : undeclared identifier
(36) : error C2065: 'd3dpp' : undeclared identifier
(36) : error C2065: 'd3dpp' : undeclared identifier
(36) : error C2070: ''unknown-type'': illegal sizeof operand
(37) : error C2065: 'd3dpp' : undeclared identifier
(37) : error C2228: left of '.Windowed' must have class/struct/union type is ''unknown-type''
(38) : error C2065: 'd3dpp' : undeclared identifier
(38) : error C2228: left of '.SwapEffect' must have class/struct/union type is ''unknown-type''
(38) : error C2065: 'D3DSWAPEFFECT_DISCARD' : undeclared identifier
(39) : error C2065: 'd3dpp' : undeclared identifier
(39) : error C2228: left of '.BackBufferFormat' must have class/struct/union type is ''unknown-type''
(39) : error C2065: 'D3DFMT_X8R8G8B8' : undeclared identifier
(40) : error C2065: 'd3dpp' : undeclared identifier
(40) : error C2228: left of '.BackBufferCount' must have class/struct/union type is ''unknown-type''
(41) : error C2065: 'd3dpp' : undeclared identifier(41) : error C2228: left of '.BackBufferWidth' must have class/struct/union type is ''unknown-type''
(42) : error C2065: 'd3dpp' : undeclared identifier
(42) : error C2228: left of '.BackBufferHeight' must have class/struct/union type is ''unknown-type''
(43) : error C2065: 'd3dpp' : undeclared identifier
(43) : error C2228: left of '.hDeviceWindow' must have class/struct/union type is ''unknown-type''
(45) : error C2227: left of '->CreateDevice' must point to class/struct/union/generic type type is 'int'
(46) : error C2065: 'D3DADAPTER_DEFAULT' : undeclared identifier
(47) : error C2065: 'D3DDEVTYPE_HAL' : undeclared identifier
(49) : error C2065: 'D3DCREATE_SOFTWARE_VERTEXPROCESSING' : undeclared identifier
(50) : error C2065: 'd3dpp' : undeclared identifier
(65) : error C2227: left of '->Clear' must point to class/struct/union/generic type type is 'int'
(65) : error C2065: 'D3DCLEAR_TARGET' : undeclared identifier
(65) : error C3861: 'D3DCOLOR_XRGB': identifier not found
(67) : error C2227: left of '->BeginScene' must point to class/struct/union/generic type type is 'int'
(71) : error C2227: left of '->EndScene' must point to class/struct/union/generic type type is 'int'
(73) : error C2227: left of '->Present' must point to class/struct/union/generic type type is 'int'
(87) : error C2227: left of '->Release' must point to class/struct/union/generic type type is 'int'
(88) : error C2227: left of '->Release' must point to class/struct/union/generic type type is 'int'

[/quote]
Advertisement
DirectX changed a lot between DirectX 9 and DirectX 11. You can't take DirectX 9 code and change it to DirectX 11 code just by changing the 9s to 11s, and there isn't a simple one to one mapping from the old functions to the new functions.

DirectX changed a lot between DirectX 9 and DirectX 11. You can't take DirectX 9 code and change it to DirectX 11 code just by changing the 9s to 11s, and there isn't a simple one to one mapping from the old functions to the new functions.





Thank you for the reply. My next question. What DX9 edition do i need for Windows 7. I have VC++ 2008, those tow should be compatible.
just use the last DX SDK...

here are some guidelines for Direct3D 11 migration..http://msdn.microsoft.com/en-us/library/ff476190(v=VS.85).aspx


just use the last DX SDK...

here are some guidelines for Direct3D 11 migration..http://msdn.microsof...0(v=VS.85).aspx




Ah, yes. this will be of service, thank you.
Okay, so I found that DX11 is backwards compatible for DX10 and DX9. I wrote the code in VS2010Professional, and made the neccessary include and library links. The links were linked to DX9 and the code compiled. However some issues persisted. Blow is the fresh code and the list of errors.


#include<windows.h>
#include<d3d9.h>
#include<time.h>
#include<iostream>
using namespace std;

const string APPTITLE = "Direct3D_Windowed";
const int SCREENW = 1024;
const int SCREENH = 768;

LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;


bool gameover = false;

#define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)&0x8000)? 1 : 0)

bool Game_Init(HWND window)
{

MessageBox(window, "Game_Init", "BREAKPOINT", 0);

d3d = Direct3DCreate9(D3D_SDK_VERSION);
if(d3d = NULL)
{
MessageBox(window, "Error initializing Direct3D", "Error", MB_OK);
return 0;
}

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREENW;
d3dpp.BackBufferHeight = SCREENH;
d3dpp.hDeviceWindow = window;

d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);

if(d3ddev = NULL)
{
MessageBox(window, "Error creating Direct3D device", "Error", MB_OK);
return 0;
}
return true;
}

void Game_Run(HWND hwnd)
{
if(!d3ddev)return;

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f, 0);

if(d3ddev->BeginScene())
{
//do something

d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);

}

if(KEY_DOWN(VK_ESCAPE))
PostMessage(hwnd, WM_DESTROY, 0,0);

}

void Game_End(HWND hwnd)
{

MessageBox(hwnd, "Program is about to end", "Game_End", MB_OK);

if(d3ddev) d3ddev->Release();
if(d3d)d3d->Release();
}

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
gameover = true;
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc =(WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE.c_str();
wc.hIconSm = NULL;
RegisterClassEx(&wc);

HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREENW, SCREENH, NULL, NULL, hInstance, NULL);

if(window == 0) return 0;

ShowWindow(window, nCmdShow);
UpdateWindow(window);

if(!Game_Init(window)) return 0;

MSG message;
while(!gameover)
{
if(PeekMessage(&message, NULL, 0,0, PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessage(&message);
}

Game_Run(window);
}
Game_End(window);

return message.wParam;

}
[/quote]


Wheh i run the program the following is generated::


ntdll.dll', Cannot find or open the PDB file
kernel32.dll', Cannot find or open the PDB file
KernelBase.dll', Cannot find or open the PDB file
d3d9.dll', Cannot find or open the PDB file
msvcrt.dll', Cannot find or open the PDB file
sechost.dll', Cannot find or open the PDB file
rpcrt4.dll', Cannot find or open the PDB file
sspicli.dll', Cannot find or open the PDB file
cryptbase.dll', Cannot find or open the PDB file
user32.dll', Cannot find or open the PDB file
gdi32.dll', Cannot find or open the PDB file
lpk.dll', Cannot find or open the PDB file
usp10.dll', Cannot find or open the PDB file
advapi32.dll', Cannot find or open the PDB file
version.dll', Cannot find or open the PDB file
d3d8thk.dll', Cannot find or open the PDB file
dwmapi.dll', Cannot find or open the PDB file
msvcp100d.dll', Symbols loaded.
'msvcr100d.dll', Symbols loaded.
apphelp.dll', Cannot find or open the PDB file
AcLayers.dll', Cannot find or open the PDB file
'shell32.dll', Cannot find or open the PDB file
shlwapi.dll', Cannot find or open the PDB file
ole32.dll', Cannot find or open the PDB file
oleaut32.dll', Cannot find or open the PDB file
userenv.dll', Cannot find or open the PDB file
'profapi.dll', Cannot find or open the PDB file
winspool.drv', Cannot find or open the PDB file
mpr.dll', Cannot find or open the PDB file
imm32.dll', Cannot find or open the PDB file
msctf.dll', Cannot find or open the PDB file
[/quote]
^ I get the feeling this has something to do with the output path.

When i press ctrl+F5, the output window is blank, as if it is running. But the window that the code is supposed to produce, does not appear.

So what am i doing wrong?
You should really check the return value of every API function you call, and when you do you should do more than return 0 when you get an error. At the very minimum for Windows API functions call GetLastError() to find out what caused the problem. In this particular case, at least one of your problems is that you didn't either 0 out or manually assign to every member of the WNDCLASSEX structure.

You should really check the return value of every API function you call, and when you do you should do more than return 0 when you get an error. At the very minimum for Windows API functions call GetLastError() to find out what caused the problem. In this particular case, at least one of your problems is that you didn't either 0 out or manually assign to every member of the WNDCLASSEX structure.


Thnak you for the reply. Sorry for thrednomancing. I'd like to request if at all possible that you augment my code. Im not too familiar with DirectX.

This topic is closed to new replies.

Advertisement