I'm not sure what's wrong, but I went through the DirectInput tutorials on the MS docs, I recieve this error... also, in the additional dependencies, I included d3d9.lib, dinput.lib and dinput8.lib.
Compiling...
winmain.cpp
Linking...
winmain.obj : error LNK2001: unresolved external symbol _GUID_SysKeyboard
winmain.obj : error LNK2001: unresolved external symbol _IID_IDirectInput8A
dinput.lib(dilib2.obj) : error LNK2001: unresolved external symbol _GUID_Key
C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\DirectX Application\Debug\DirectX Application.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\DirectX Application\DirectX Application\Debug\BuildLog.htm"
DirectX Application - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include
<windows.h>#include
<windowsx.h>#include
<iostream>#include
<d3d9.h>#include
<d3dx9tex.h>#define
DIRECTINPUT_VERSION 0x0800#include
<dinput.h>const
char *g_szClassName = "WNDCLASS1";const
char *g_szWinTitle = "DirectX Application";const
int g_width = 800;const
int g_height = 600;HWND g_hWnd = NULL;
HINSTANCE g_hInstance;
bool
bFullScreen = false;LPDIRECT3D9 pD3D = NULL;
LPDIRECT3DDEVICE9 pd3dDevice = NULL;
LPDIRECTINPUT8 lpDI = NULL;
LPDIRECTINPUTDEVICE8 lpDIDevice = NULL;
#define KEYDOWN(name, key) (name[key] & 0x80)
// Prototypes
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int
GetInput(void);int
Game_Init(void);int
Game_Render(void);int
Game_Destroy(void);int
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
HWND hWnd = NULL;
MSG msg;
DWORD windowStyle;
// Create the parent window class.WNDCLASSEX wc;
wc.cbClsExtra = 0;
wc.cbSize =
sizeof(WNDCLASSEX);wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = g_szClassName;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
// Register the parent window class. if (!RegisterClassEx(&wc)) {MessageBox(NULL,
"Registering the parent window failed.", g_szWinTitle, MB_OK | MB_ICONERROR); return 0;}
// Is this a full screen session Set window style accordingly. if (bFullScreen)windowStyle = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;
elsewindowStyle = WS_OVERLAPPEDWINDOW;
// Create the parent windowhWnd = CreateWindowEx(NULL, g_szClassName, g_szWinTitle, windowStyle, CW_USEDEFAULT,
CW_USEDEFAULT, g_width, g_height, NULL, NULL, hInstance, NULL);
if (hWnd == NULL) {MessageBox(NULL,
"Creating the parent window failed.", g_szWinTitle, MB_OK | MB_ICONERROR); return 0;}
// Store global variables.g_hWnd = hWnd;
g_hInstance = hInstance;
// Show & Update WindowShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
Game_Init();
// Message Loop while (TRUE){
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if (msg.message == WM_QUIT) break;TranslateMessage(&msg);
DispatchMessage(&msg);
}
GetInput();
Game_Render();
}
Game_Destroy();
return (int) msg.wParam;}
// Message Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
switch (msg){
case WM_CREATE:{
}
break; case WM_PAINT:{
hDC = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
break; case WM_CLOSE:{
}
break; case WM_DESTROY:{
PostQuitMessage(WM_QUIT);
}
break; default: break;}
return DefWindowProc(hWnd, msg, wParam, lParam);}
// Get all input here.
int
GetInput(void){
// Did the user hit escape //if (KEYDOWN(VK_ESCAPE)) //SendMessage(g_hWnd, WM_CLOSE, 0, 0); char buffer[256];HRESULT hr;
hr = lpDIDevice->GetDeviceState(
sizeof(buffer), (LPVOID)&buffer); if (FAILED(hr)) return 0; if (KEYDOWN(buffer, DIK_ESCAPE))SendMessage(g_hWnd, WM_CLOSE, 0, 0);
return 1;}
// Do all game initialization here.
int
Game_Init(void){
// Create the Direct3D object if (NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))) {MessageBox(NULL,
"Error creating d3d object.", g_szWinTitle, MB_OK | MB_ICONERROR);SendMessage(g_hWnd, WM_CLOSE, 0, 0);
}
// Create the presentation parametersD3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,
sizeof(d3dpp)); // Is this a full screen session if (bFullScreen) {d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.Windowed =
false;}
else {d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.Windowed =
true;}
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = g_width;
d3dpp.BackBufferHeight = g_height;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = g_hWnd;
// Create the Direct3D Device if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice))) {
MessageBox(NULL,
"Error creating device.", g_szWinTitle, MB_OK | MB_ICONERROR);SendMessage(g_hWnd, WM_CLOSE, 0, 0);
}
/*****
Initialize DirectInput here.
*****/
HRESULT hr;
hr = DirectInput8Create(g_hInstance, DIRECTINPUT_VERSION,
IID_IDirectInput8, (
void **)&lpDI, NULL); if (FAILED(hr)) return 0; // Create the direct input devicehr = lpDI->CreateDevice(GUID_SysKeyboard, &lpDIDevice, NULL);
if (FAILED(hr)) return 0; // Set the data formathr = lpDIDevice->SetDataFormat(&c_dfDIKeyboard);
if (FAILED(hr)) return 0; // Set the cooperation levelhr = lpDIDevice->SetCooperativeLevel(g_hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(hr)) return 0; // Aquire access to the devicehr = lpDIDevice->Acquire();
if (FAILED(hr)) return 0; return 1;}
// Main game logic here.
int
Game_Render(void){
if (NULL == pd3dDevice) return 0;pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
pd3dDevice->Present(NULL, NULL, NULL, NULL);
return 1;}
// Deallocate resources and other cleanup here.
int
Game_Destroy(void){
if (lpDIDevice) {lpDIDevice->Unacquire();
}
if (lpDIDevice != NULL) {lpDIDevice->Release();
lpDIDevice = NULL;
}
if (lpDI != NULL) {lpDI->Release();
lpDI = NULL;
}
if (pd3dDevice != NULL) {pd3dDevice->Release();
pd3dDevice = NULL;
}
if (pD3D != NULL) {pD3D->Release();
pD3D = NULL;
}
return 1;}

Compile time error with DirectInput
Ryan Rinaldi
Alf928
I don't think the *entire* code listing is particularly useful here
Anyway, if you load up the keyboard_2005.sln solution from the SDK you'll see that there is a slightly different set of libraries used:
dxguid.lib dxerr.lib dinput8.lib comctl32.lib
I would interpret your linker errors as being due to missing out dxguid.lib.
hth
Jack
ecofriend
Using DirectInput, I receive basically the same linker error as dxfoo. I am using .NET 2003.
I included all of the libs mentioned, but I'm still not linking --
Linking...
LINK : error LNK2020: unresolved token (0A00002F) IID_IDirectInput8A
LINK : fatal error LNK1120: 1 unresolved externals
Any suggestions, please