Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


DirectX Input Init

This topic is 5491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m trying to implement simple Keyboard support via Direct Input but somehow it just doesn''t work. This is the Code I''m using to initialize DInput //DInit BOOL DI_Init(HINSTANCE g_hinst, HWND g_hwndMain) { HRESULT hr; // Create the DirectInput object. hr = DirectInput8Create(g_hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_lpDI, NULL); if FAILED(hr) return FALSE; // Retrieve a pointer to an IDirectInputDevice8 interface hr = g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL); if FAILED(hr) { DI_Term(); return FALSE; } // Now that you have an IDirectInputDevice8 interface, get // it ready to use. // Set the data format using the predefined keyboard data // format provided by the DirectInput object for keyboards. hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard); if FAILED(hr) { DI_Term(); return FALSE; } // Set the cooperative level hr = g_lpDIDevice->SetCooperativeLevel(g_hwndMain, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); if FAILED(hr) { DI_Term(); return FALSE; } // Get access to the input device. hr = g_lpDIDevice->Acquire(); if FAILED(hr) { DI_Term(); return FALSE; } return TRUE; } DI_Term is not important I think since its just for releasing the Input Objects after the problem has ocurred. The main problem of this seems to be that the programm is not able to acquire the device. FAILED(hr) seems to be true when the function tries to acquite the device even though everything else seems to work. The call to the function is made in WinMain, here: (The program worked before I put the function in and works if I take it out again) INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ) { // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "D3D Tutorial", NULL }; RegisterClassEx( &wc ); // Create the application''s window HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 04: Lights", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL ); if(DI_Init(hInst,hWnd)){ // Initialize Direct3D if( SUCCEEDED( InitD3D( hWnd, hInst ) ) ) { // Create the geometry if( SUCCEEDED( InitGeometry() ) ) { // Show the window ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); // Enter the message loop MSG msg; ZeroMemory( &msg, sizeof(msg) ); while( msg.message!=WM_QUIT ) { if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else Render(); } } } } UnregisterClass( "D3D Tutorial", wc.hInstance ); return 0; }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!