   input not working...
#include <windows.h>#include <stdio.h>#include <d3d8.h>#include <d3dx8.h>#include <dinput.h>//Globalchar *g_WindowClass = "Game";char *g_WindowName = "Game";HWND g_hWnd;//graphic-based globelsIDirect3D8 *g_d3d; //globel for device checking and settingIDirect3DDevice8 *g_d3dd; //device for the vertex drawingIDirectInput8 *g_pDI;IDirectInputDevice8 *g_pDID;IDirectInputDevice8 *keyboard;#define KeyState(x) ((KeyStateBuffer[x] & 0x80) ? true : false)//Main PrototypesHWND CreateNewWindow(HINSTANCE, char *, char *, int, int);bool RegisterWindow(HINSTANCE, char *);bool UnRegisterWindow(HINSTANCE, char *);bool Init();bool PreFrame();bool PerFrame();bool PostFrame();IDirectInputDevice8 *InitKeyboard(HWND hWnd, IDirectInput8 *pDI);bool ReadDevice(IDirectInputDevice8 *pDIDevice, void *DataBuffer, long BufferSize);int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow){    MSG msg;char KeyStateBuffer[256];//Regeister New WindowDirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_pDI, NULL);g_pDID = InitKeyboard(g_hWnd, g_pDI);RegisterWindow(hInst, g_WindowClass);CreateNewWindow(hInst, g_WindowClass, g_WindowName, 800, 600);if(Init() == false)MessageBox(g_hWnd, "test", "test", MB_OK);if((keyboard = InitKeyboard(g_hWnd, g_pDI)) == NULL)MessageBox(g_hWnd, "test", "test", MB_OK);while(msg.message != WM_QUIT){if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){TranslateMessage (&msg);DispatchMessage (&msg);}ReadDevice(g_pDID, (void*)KeyStateBuffer, 256);if((KeyState(VK_LEFT) == true))MessageBox(g_hWnd, "test", "test", MB_OK);} g_pDID->Unacquire(); g_pDID->Release();g_pDI->Release();UnRegisterWindow(hInst, g_WindowClass);return msg.wParam; }LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){    switch (iMsg)    {case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc (hwnd, iMsg, wParam, lParam);}//Create a New WidnowHWND CreateNewWindow(HINSTANCE hInst,char *WindowClass, char *WindowClassName, int WindowWidth, int WindowHeight){HWND hWnd; hWnd = CreateWindow (WindowClass, WindowClassName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, WindowWidth, WindowHeight, NULL, NULL, hInst, NULL); ShowWindow(hWnd, SW_NORMAL);    UpdateWindow(hWnd);g_hWnd = hWnd;return hWnd;}//Register New Windowbool RegisterWindow(HINSTANCE hInst, char *WindowClass){WNDCLASSEX  wndclass;    wndclass.cbSize   = sizeof (wndclass);    wndclass.style    = CS_HREDRAW | CS_VREDRAW;    wndclass.lpfnWndProc   = WndProc;    wndclass.cbClsExtra    = 0;    wndclass.cbWndExtra    = 0;    wndclass.hInstance= hInst;    wndclass.hIcon    = LoadIcon (NULL, IDI_WINLOGO);    wndclass.hCursor  = LoadCursor (NULL, IDC_ARROW);    wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);    wndclass.lpszMenuName  = NULL;    wndclass.lpszClassName = WindowClass;    wndclass.hIconSm  = LoadIcon (NULL, IDI_WINLOGO);RegisterClassEx (&wndclass);return true;}//UnRegesterWindowbool UnRegisterWindow(HINSTANCE hInst, char *WindowClass){UnregisterClass(WindowClass,hInst);return true;}bool Init(){  D3DPRESENT_PARAMETERS d3dpp; //display parameters  D3DDISPLAYMODE   d3ddm; //display mode  //window intinalization  //creates a object taht allows creation of other objects  if((g_d3d = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)    return false;  //gets Display Mode  if(FAILED(g_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))    return false;  //clears the present parameters  ZeroMemory(&d3dpp, sizeof(d3dpp));  //set the present parameters  d3dpp.Windowed = true; //tellss compiler its windowed  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //what do so with enpty buffer  d3dpp.BackBufferFormat = d3ddm.Format; //format of backbuffer  d3dpp.EnableAutoDepthStencil = false;  //create display Device  if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,    D3DCREATE_SOFTWARE_VERTEXPROCESSING,    &d3dpp, &g_d3dd)))return false;  return true;}bool PerFrame(){  return true;}IDirectInputDevice8 *InitKeyboard(HWND hWnd, IDirectInput8 *pDI){IDirectInputDevice8 *pDIDevice;if(FAILED(pDI->CreateDevice(GUID_SysKeyboard, &pDIDevice, NULL)))return false;if(FAILED(pDIDevice->SetDataFormat(&c_dfDIKeyboard))){pDIDevice->Release();return NULL;}if(FAILED(pDIDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))){pDIDevice->Release();return NULL;}if(FAILED(pDIDevice->Acquire())){pDIDevice->Release();return NULL;}return pDIDevice;}bool ReadDevice(IDirectInputDevice8 *pDIDevice,\ void *DataBuffer, long BufferSize){  HRESULT hr;  while(1) {    // Poll device    g_pDID->Poll();    // Read in state    if(SUCCEEDED(hr = g_pDID->GetDeviceState(BufferSize,(LPVOID)DataBuffer))) break;    // Return on an unknown error if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED) return false;    // Reacquire and try again    if(FAILED(g_pDID->Acquire())) return false;  }  // Return a success  return true;}i get an error when i compile it and the debugger points to the g_pDID->Poll anyone tell me what i have wrong 
  first of all, whats the error? and also did you use the debugger. Becuase when a directx call fails, direcx outputs the reason for teh error to the debug output window.   :::: [ Triple Buffer V2.0 ] ::::;  debugger points to the g_pDID->Poll anyone tell me what i have wrong ...i posted where it says debugger had a problem....when i run the program it get a 0xC0000005 access violation ;  ok that means that your g_pDID is not right. inside your InitKeyboard function try getting rid of the if(FAILED(g_pDID->Acquire()))) {}check. Becuase this call can easily fail. So it might be that this is failing and you release the device and pass back a released pointer, which is why it''s invalid.this *might* be your problem.   :::: [ Triple Buffer V2.0 ] ::::;  hmm stilld ont work not when i run it i get a0x0040CFoB Referenced Memory 0x00000000 COuld not be Read.  Points to same part of code still. ;  ok, looked htrough again and noticed that you're calling the InitKeyboard function before initializing your window. This means that the HWND (g_hwnd) is invalid. So dinput cannot create the keyboard device with an invalid window handle.try calling your CreateNewWindow before calling InitKeyboard. Also noticed that you're not releasing your d3d objects.Here. This works now. I got rid of the if statement when calling g_DID->Acquire(). I called CreateNewWindow before InitKeyboard. and I added g_pd3d->Release() and g_d3d->Release() to the end of the program #pragma comment( lib, "dinput8.lib" )#pragma comment( lib, "d3d8.lib" )#pragma comment( lib, "dxguid.lib" )#include <windows.h>#include <stdio.h>#include <d3d8.h>#include <d3dx8.h>#include <dinput.h>//Globalchar *g_WindowClass = "Game";char *g_WindowName = "Game";HWND g_hWnd;//graphic-based globelsIDirect3D8 *g_d3d; //globel for device checking and settingIDirect3DDevice8 *g_d3dd; //device for the vertex drawingIDirectInput8 *g_pDI;IDirectInputDevice8 *g_pDID;IDirectInputDevice8 *keyboard;#define KeyState(x) ((KeyStateBuffer[x] & 0x80) ? true : false)//Main PrototypesHWND CreateNewWindow(HINSTANCE, char *, char *, int, int);bool RegisterWindow(HINSTANCE, char *);bool UnRegisterWindow(HINSTANCE, char *);bool Init();bool PreFrame();bool PerFrame();bool PostFrame();IDirectInputDevice8 *InitKeyboard(HWND hWnd, IDirectInput8 *pDI);bool ReadDevice(IDirectInputDevice8 *pDIDevice, void *DataBuffer, long BufferSize);int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){   MSG msg;    memset( &msg, 0, sizeof(MSG) );    char KeyStateBuffer[256];    //Regeister New Window   DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_pDI, NULL);  RegisterWindow(hInst, g_WindowClass);   CreateNewWindow(hInst, g_WindowClass, g_WindowName, 800, 600);    g_pDID = InitKeyboard(g_hWnd, g_pDI);   if(Init() == false)   MessageBox(g_hWnd, "test", "test", MB_OK);   if((keyboard = InitKeyboard(g_hWnd, g_pDI)) == NULL)   MessageBox(g_hWnd, "test", "test", MB_OK);   while(msg.message != WM_QUIT)    {   if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {  TranslateMessage (&msg);  DispatchMessage (&msg);   } ReadDevice(g_pDID, (void*)KeyStateBuffer, 256); if((KeyState(VK_LEFT) == true))  MessageBox(g_hWnd, "test", "test", MB_OK);    }    g_pDID->Unacquire();g_pDID->Release();    g_pDI->Release();    g_d3dd->Release();    g_d3d->Release();   UnRegisterWindow(hInst, g_WindowClass);    return 0; }LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){   switch (iMsg)   {    case WM_DESTROY:   PostQuitMessage(0);   break;    }   return DefWindowProc (hwnd, iMsg, wParam, lParam);}//Create a New WidnowHWND CreateNewWindow(HINSTANCE hInst,char *WindowClass, char *WindowClassName, int WindowWidth, int WindowHeight){    HWND hWnd;hWnd = CreateWindow (WindowClass, WindowClassName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,   CW_USEDEFAULT, WindowWidth, WindowHeight, NULL, NULL, hInst, NULL);    ShowWindow(hWnd, SW_NORMAL);   UpdateWindow(hWnd);    g_hWnd = hWnd;    return hWnd;}//Register New Windowbool RegisterWindow(HINSTANCE hInst, char *WindowClass){    WNDCLASSEX  wndclass;   wndclass.cbSize   = sizeof (wndclass);   wndclass.style    = CS_HREDRAW | CS_VREDRAW;   wndclass.lpfnWndProc   = WndProc;   wndclass.cbClsExtra    = 0;   wndclass.cbWndExtra    = 0;   wndclass.hInstance= hInst;   wndclass.hIcon    = LoadIcon (NULL, IDI_WINLOGO);   wndclass.hCursor  = LoadCursor (NULL, IDC_ARROW);   wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);   wndclass.lpszMenuName  = NULL;   wndclass.lpszClassName = WindowClass;   wndclass.hIconSm  = LoadIcon (NULL, IDI_WINLOGO);    RegisterClassEx (&wndclass);    return true;}//UnRegesterWindowbool UnRegisterWindow(HINSTANCE hInst, char *WindowClass){    UnregisterClass(WindowClass,hInst);    return true;}bool Init(){ D3DPRESENT_PARAMETERS d3dpp; //display parameters D3DDISPLAYMODE   d3ddm; //display mode//window intinalization //creates a object taht allows creation of other objectsif((g_d3d = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)  return false;//gets Display Mode if(FAILED(g_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))  return false;//clears the present parameters ZeroMemory(&d3dpp, sizeof(d3dpp)); //set the present parameters d3dpp.Windowed = true; //tellss compiler its windowed d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //what do so with enpty buffer d3dpp.BackBufferFormat = d3ddm.Format; //format of backbuffer d3dpp.EnableAutoDepthStencil = false;  //create display Deviceif(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,   D3DCREATE_SOFTWARE_VERTEXPROCESSING,  &d3dpp, &g_d3dd)))   return false;return true;}bool PerFrame(){ return true;}IDirectInputDevice8 *InitKeyboard(HWND hWnd, IDirectInput8 *pDI){    IDirectInputDevice8 *pDIDevice;    if(FAILED(pDI->CreateDevice(GUID_SysKeyboard, &pDIDevice, NULL)))   return false;    if(FAILED(pDIDevice->SetDataFormat(&c_dfDIKeyboard)))    {   pDIDevice->Release();   return NULL;    }   if(FAILED(pDIDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))    {   pDIDevice->Release();   return NULL;    }   pDIDevice->Acquire();   return pDIDevice;}bool ReadDevice(IDirectInputDevice8 *pDIDevice,  void *DataBuffer, long BufferSize){ HRESULT hr; while(1){  // Poll device  g_pDID->Poll();// Read in state  if(SUCCEEDED(hr = g_pDID->GetDeviceState(BufferSize,(LPVOID)DataBuffer)))   break;// Return on an unknown error    if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED)   return false;// Reacquire and try again  if(FAILED(g_pDID->Acquire()))   return false; }// Return a success return true;} ::::   [ Triple Buffer V2.0 ] ::::  [edited by - ifoobar on July 30, 2003 11:12:13 AM];  alright it dones''t give me anymore errors but the code part that this book has an''t acpeitn the input...inthe messagepump i check to see if VK_LEFT was pressed...but when i press left it dont create the message box. ;  The macro KeyState dosnt return true if a key is pressed it just returns a non-zero number. So doing thisKeyState(VK_LEFT) == truejust checks if KeyState(VK_LEFT) == 1. becuase true is 1. You just need to check if it''s not 0 likeKeyState(VK_LEFT) != 0orKeyState(VK_LEFT) != falsebecause false is also 0.   :::: [ Triple Buffer V2.0 ] ::::;  i didn''t wanna make a new thread for this...not i have a problem with mouse...no errors just...when i run it...the mouse check to see if leftbutton was pressed seems messed up.  WHen i run the program a message box pops up over and over and over again never stoping...whehter buttonis pressed or not #include <windows.h>#include <stdio.h>#include <d3d8.h>#include <d3dx8.h>#include <dinput.h>//Globalchar *g_WindowClass = "Game";char *g_WindowName = "Game";HWND g_hWnd;//graphic-based globels - input basedIDirect3D8 *g_d3d; //globel for device checking and settingIDirect3DDevice8 *g_d3dd; //device for the vertex drawingIDirectInput8 *g_pDI;IDirectInputDevice8 *g_pDID;IDirectInputDevice8 *keyboard;IDirectInputDevice8 *mouse;long MouseX, MouseY;//mouse bufferDIMOUSESTATE MouseState;#define KeyState(x) ((KeyStateBuffer[x] & 0x80) ? true : false)//Main PrototypesHWND CreateNewWindow(HINSTANCE, char *, char *, int, int);bool RegisterWindow(HINSTANCE, char *);bool UnRegisterWindow(HINSTANCE, char *);bool Init();bool PreFrame();bool PerFrame();bool PostFrame();IDirectInputDevice8 *InitKeyboard(HWND hWnd, IDirectInput8 *pDI);IDirectInputDevice8 *InitMouse(HWND hWnd, IDirectInput8 *pDI);bool ReadDevice(IDirectInputDevice8 *pDIDevice, void *DataBuffer, long BufferSize);bool Update();int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow){#define MouseButtonState(x) ((MouseState.rgbButtons[x] & 0x80) ? true : false)    MSG msg;char KeyStateBuffer[256];//Regeister New WindowRegisterWindow(hInst, g_WindowClass);CreateNewWindow(hInst, g_WindowClass, g_WindowName, 800, 600);DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_pDI, NULL);g_pDID = InitKeyboard(g_hWnd, g_pDI);Init();keyboard = InitKeyboard(g_hWnd, g_pDI);mouse = InitMouse(g_hWnd, g_pDI);while(msg.message != WM_QUIT){if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){TranslateMessage (&msg);DispatchMessage (&msg);}ReadDevice(g_pDID, (void*)KeyStateBuffer, 256);Update();if(MouseState.rgbButtons[0] & 0x80)MessageBox(g_hWnd, "test", "test", MB_OK);if(KeyStateBuffer[DIK_A] & 0x80)MessageBox(g_hWnd, "test", "test", MB_OK);} g_pDID->Unacquire(); g_pDID->Release(); g_pDI->Release(); g_d3d->Release(); g_d3dd->Release(); mouse->Unacquire();mouse->Release();mouse = NULL;UnRegisterWindow(hInst, g_WindowClass);return msg.wParam; }LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){    switch (iMsg)    {case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc (hwnd, iMsg, wParam, lParam);}//Create a New WidnowHWND CreateNewWindow(HINSTANCE hInst,char *WindowClass, char *WindowClassName, int WindowWidth, int WindowHeight){HWND hWnd; hWnd = CreateWindow (WindowClass, WindowClassName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, WindowWidth, WindowHeight, NULL, NULL, hInst, NULL); ShowWindow(hWnd, SW_NORMAL);    UpdateWindow(hWnd);g_hWnd = hWnd;return hWnd;}//Register New Windowbool RegisterWindow(HINSTANCE hInst, char *WindowClass){WNDCLASSEX  wndclass;    wndclass.cbSize   = sizeof (wndclass);    wndclass.style    = CS_HREDRAW | CS_VREDRAW;    wndclass.lpfnWndProc   = WndProc;    wndclass.cbClsExtra    = 0;    wndclass.cbWndExtra    = 0;    wndclass.hInstance= hInst;    wndclass.hIcon    = LoadIcon (NULL, IDI_WINLOGO);    wndclass.hCursor  = LoadCursor (NULL, IDC_ARROW);    wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);    wndclass.lpszMenuName  = NULL;    wndclass.lpszClassName = WindowClass;    wndclass.hIconSm  = LoadIcon (NULL, IDI_WINLOGO);RegisterClassEx (&wndclass);return true;}//UnRegesterWindowbool UnRegisterWindow(HINSTANCE hInst, char *WindowClass){UnregisterClass(WindowClass,hInst);return true;}bool Init(){  D3DPRESENT_PARAMETERS d3dpp; //display parameters  D3DDISPLAYMODE   d3ddm; //display mode  //window intinalization  //creates a object taht allows creation of other objects  if((g_d3d = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)    return false;  //gets Display Mode  if(FAILED(g_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))    return false;  //clears the present parameters  ZeroMemory(&d3dpp, sizeof(d3dpp));  //set the present parameters  d3dpp.Windowed = true; //tellss compiler its windowed  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //what do so with enpty buffer  d3dpp.BackBufferFormat = d3ddm.Format; //format of backbuffer  d3dpp.EnableAutoDepthStencil = false;  //create display Device  if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,    D3DCREATE_SOFTWARE_VERTEXPROCESSING,    &d3dpp, &g_d3dd)))return false;  return true;}bool PerFrame(){  return true;}IDirectInputDevice8 *InitKeyboard(HWND hWnd, IDirectInput8 *pDI){IDirectInputDevice8 *pDIDevice;if(FAILED(pDI->CreateDevice(GUID_SysKeyboard, &pDIDevice, NULL)))return false;if(FAILED(pDIDevice->SetDataFormat(&c_dfDIKeyboard))){pDIDevice->Release();return NULL;}if(FAILED(pDIDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))){pDIDevice->Release();return NULL;}return pDIDevice;}IDirectInputDevice8 *InitMouse(HWND hWnd, IDirectInput8 *pDI){IDirectInputDevice8 *pDID;if(FAILED(pDI->CreateDevice(GUID_SysMouse, &pDID, NULL)))return NULL;if(FAILED(pDID->SetDataFormat(&c_dfDIMouse))){pDID->Release();return NULL;}if(FAILED(pDID->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))){pDID->Release();return NULL;}if(FAILED(pDID->Acquire())){pDID->Unacquire();pDID->Release();return NULL;}return pDID;}bool ReadDevice(IDirectInputDevice8 *pDIDevice, void *DataBuffer, long BufferSize){  HRESULT hr;  while(1) {    // Poll device    g_pDID->Poll();    // Read in state    if(SUCCEEDED(hr = g_pDID->GetDeviceState(BufferSize,(LPVOID)DataBuffer))) break;    // Return on an unknown error if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED) return false;    // Reacquire and try again    if(FAILED(g_pDID->Acquire())) return false;  }  // Return a success  return true;}bool Update(){  if (FAILED(mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&MouseState)))    return false;  return true;};  been a while anyone know...be really apriceiatedsry for bumbing 