Beispiel #1
1
void MOUSE::InitMouse(IDirect3DDevice9* Dev, HWND wnd)
{
	try
	{
		m_pDevice = Dev;

		//Load texture and init sprite
		D3DXCreateTextureFromFile(m_pDevice, "cursor/cursor.dds", &m_pMouseTexture);
		D3DXCreateSprite(m_pDevice, &m_pSprite);

		//Get directinput object
		LPDIRECTINPUT8 directInput = NULL;

		DirectInput8Create(GetModuleHandle(NULL),	// Retrieves the application handle
						   0x0800,					// v.8.0	
						   IID_IDirectInput8,		// Interface ID
						   (VOID**)&directInput,	// Our DirectInput Object
						   NULL);

		//Acquire Default System mouse
		directInput->CreateDevice(GUID_SysMouse, &m_pMouseDevice, NULL);		
		m_pMouseDevice->SetDataFormat(&c_dfDIMouse);
		m_pMouseDevice->SetCooperativeLevel(wnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
		m_pMouseDevice->Acquire();	        

		//Get viewport size and init mouse location
		D3DVIEWPORT9 v;
		m_pDevice->GetViewport(&v);
		m_viewport.left = v.X;
		m_viewport.top = v.Y;
		m_viewport.right = v.X + v.Width;
		m_viewport.bottom = v.Y + v.Height;

		x = v.X + v.Width / 2;
		y = v.Y + v.Height / 2;

		//Release Direct Input Object
		directInput->Release();

		//Create Mouse Sphere
		D3DXCreateSphere(m_pDevice, 0.2f, 5, 5, &m_pSphereMesh, NULL);

		//Create Ball Material
		m_ballMtrl.Diffuse = D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f);
		m_ballMtrl.Specular = m_ballMtrl.Ambient = m_ballMtrl.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	}
	catch(...)
	{
		debug.Print("Error in MOUSE::InitMouse()");
	}	
}
Beispiel #2
0
DXInput::~DXInput()
{
    traceIn(DXInput::~DXInput);

    bInputExiting = 1;

    SetEvent(InputEvents[0]);
    SetEvent(InputEvents[1]);
    //WaitForSingleObject(hInputThread, 5000);
    //CloseHandle(hInputThread);
    diKeyboard->SetEventNotification(NULL);
    diMouse->SetEventNotification(NULL);
    CloseHandle(InputEvents[0]);
    CloseHandle(InputEvents[1]);

    DIDestroyKeyboardDevice();
    DIDestroyMouseDevice();
    diDevice->Release();

    bDInputActive = 0;

    Log(TEXT("DirectInput Freed"));

    traceOut;
}
Beispiel #3
0
// リソースの解放
void CleanupD3D()
{
	for (int i = 0; i < MAXMODEL; i = i + 1)
	{
		if (g_models[i].used == TRUE)
		{
			if (g_models[i].pmaterials != NULL)
			{
				delete[] g_models[i].pmaterials;
			}
			if (g_models[i].ptextures != NULL)
			{
				for (DWORD j = 0; j < g_models[i].nummaterials; j = j + 1)
				{
					g_models[i].ptextures[j]->Release();
				}
				delete[] g_models[i].ptextures;
			}
			if (g_models[i].pmesh != NULL)
			{
				g_models[i].pmesh->Release();
			}
		}
	}
	if (g_pd3dDevice != NULL) g_pd3dDevice->Release();
	if (g_pD3D != NULL) g_pD3D->Release();

	if (g_pDIDevice != NULL)
	{
		g_pDIDevice->Unacquire();
		g_pDIDevice->Release();
	}
	if (g_pDI != NULL) g_pDI->Release();
}
int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// kill the bug blaster
Destroy_BOB(&blaster);

// kill the mushroom maker
for (int index=0; index<4; index++)
    Destroy_Bitmap(&mushrooms[index]);

// kill the playfield bitmap
Destroy_Bitmap(&playfield);

// release joystick
lpdijoy->Unacquire();
lpdijoy->Release();
lpdi->Release();

// shutdonw directdraw
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
Beispiel #5
0
void destroyDevice()
{
	// Destruction des objets Direct3D
	if(g_pD3DDevice)
		g_pD3DDevice->ClearState();
	if(g_pRenderTargetView)
		g_pRenderTargetView->Release();
	if(g_pSwapChain)
		g_pSwapChain->Release();
	if(g_pD3DDevice)
		g_pD3DDevice->Release();

	// Destruction des objets DirectInput
	if(g_pKeyboardDevice)
	{
		g_pKeyboardDevice->Unacquire();
		g_pKeyboardDevice->Release();
	}
	if(g_pMouseDevice)
	{
		g_pMouseDevice->Unacquire();
		g_pMouseDevice->Release();
	}
	if(g_pDI)
		g_pDI->Release();
}
void PsychHIDShutdownHIDStandardInterfaces(void)
{
    int i;

    // Release all keyboard queues:
    for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) {
        if (psychHIDKbQueueFirstPress[i]) {
            PsychHIDOSKbQueueRelease(i);
        }
    }

    // Close all devices registered in x_dev array:
    for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) {
        if (x_dev[i]) x_dev[i]->Release();
        x_dev[i] = NULL;
    }

    // Release keyboard queue mutex:
    PsychDestroyMutex(&KbQueueMutex);
    PsychDestroyCondition(&KbQueueCondition);
    KbQueueThreadTerminate = FALSE;

    if (!CloseHandle(hEvent)) {
        printf("PsychHID-WARNING: Closing keyboard event handle failed!\n");
    }

    ndevices = 0;

    // Close our dedicated x-display connection and we are done:
    if (dinput) dinput->Release();
    dinput = NULL;

    return;
}
int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// first unacquire the mouse
lpdimouse->Unacquire();

// now release the mouse
lpdimouse->Release();

// release directinput
lpdi->Release();

// unload the bitmap file
Unload_Bitmap_File(&bitmap8bit);

// delete all bobs and bitmaps
Destroy_BOB(&buttons);
Destroy_BOB(&pointer);
Destroy_Bitmap(&cpanel);
Destroy_Bitmap(&canvas);

// shutdonw directdraw
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
Beispiel #8
0
void Done_DInput()
{
	for( int lcv = 0; lcv < di_mouse_count; lcv++ ) {
		if( di_mouse[ lcv ] ) {
			di_mouse[ lcv ]->Unacquire();
			di_mouse[ lcv ]->Release();
			di_mouse[ lcv ] = NULL;
		}
	}


	for( int lcv = 0; lcv < di_joystick_count; lcv++ ) {
		if( di_joystick[ lcv ] ) {
			di_joystick[ lcv ]->Unacquire();
			di_joystick[ lcv ]->Release();
			di_joystick[ lcv ] = NULL;
		}
	}


	if( di_keyboard ) {
		di_keyboard->Unacquire();
		di_keyboard->Release();
		di_keyboard = NULL;
	}


	if( dinput ) {
		dinput->Release();
		dinput = NULL;
	}


	di_mouse_count = 0;
}
Beispiel #9
0
void disposeDirectInput()
{
    logg( "    Disposing Keyboard...", false );
    dinKeyboard->Unacquire();    // make sure the keyboard is unacquired
    dinKeyboard = NULL;
    logg( " Successfully disposed Keyboard." );
    
    logg( "    Disposing Joysticks...", false );
    for ( int i = numJoysticks - 1; i >= 0; i-- )
    {
        try
        {
            dinJoysticks[i]->Unacquire();
            dinJoysticks[i]->Release();
        }
        catch ( ... )
        {
            loggui( " WARNING: Caught an exception while trying to dispose Joystick ", i );
        }
        
        dinJoysticks[i] = NULL;
    }
    logg( " Successfully disposed Joysticks." );
    
    logg( "    Disposing DirectInput...", false );
    din->Release();    // close DirectInput before exiting
    din = NULL;
    logg( " Successfully disposed DirectInput." );
}
Beispiel #10
0
INT_PTR WINAPI messageCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	switch (message) {
		case WM_DEVICECHANGE:
			if (wParam ==  DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {
				// Wait for 30 frames, send refresh
				mustRefreshDevices = 30;
			}
			break;

		case WM_CLOSE:
			UnregisterDeviceNotification(hDeviceNotify);
			DestroyWindow(hWnd);

			diAvailable = false;
			// Releasing resources to avoid crashes
			for (auto it : joysticks) {
				if (it.second) {
					it.second->Unacquire();
					it.second->Release();
				}
			}
			joysticks.clear();
			if (di) {
				di->Release();
			}
			di = NULL;
			break;

		default:
			// Send all other messages on to the default windows handler.
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 1;
}
Beispiel #11
0
void DInput_Shutdown(void)
{
// this function shuts down directinput

if (lpdi)
   lpdi->Release();

} // end DInput_Shutdown
Beispiel #12
0
//=============================================================================
// 入力処理の終了処理
//=============================================================================
void UninitInput(void)
{
	// DirectInputオブジェクトの開放
	if(g_pInput)
	{
		g_pInput->Release();
		g_pInput = NULL;
	}
}
void ShutdownJoystick()
{
    // Unacquire the device one last time just in case
    // the app tried to exit while the device is still acquired.
    if( gJoystick )
        gJoystick->Unacquire();

    // Release any DirectInput objects.
    if(gJoystick)
        gJoystick->Release();
    if(gDirectInput)
        gDirectInput->Release();
}
Beispiel #14
0
/////////////////////////////////////
// Name:	INPXDestroy
// Purpose:	this will terminate DInput
//			as well as all the other devices
// Output:	everything destroyed
// Return:	none
/////////////////////////////////////
PUBLIC void INPXDestroy()
{
	INPXKeyboardDestroy();
	INPXJoystickDestroyAll();

	if(g_pDInput)
	{
		g_pDInput->Release();
		g_pDInput=0;
	}

	g_joystickEnums.clear();
	g_joystickEnums.resize(0);
}
//=============================================================================
// 入力処理の終了処理
//=============================================================================
void UninitInput(void)
{
	// キーボードの終了処理
	UninitKeyboard();

	// マウスの終了処理
	UninitMouse();

	if(g_pDInput)
	{
		g_pDInput->Release();
		g_pDInput = NULL;
	}
}
Beispiel #16
0
void disposeDirectInput()
{
    dinKeyboard->Unacquire();    // make sure the keyboard is unacquired
    dinKeyboard = NULL;
    
    for ( int i = numJoysticks - 1; i >= 0; i-- )
    {
        dinJoysticks[i]->Unacquire();
        dinJoysticks[i]->Release();
        
        dinJoysticks[i] = NULL;
    }
    
    din->Release();    // close DirectInput before exiting
    din = NULL;
}
bool ReleaseObjects()
{
	if (d3dDevice) d3dDevice->ClearState();

	if (VertexBuffer) VertexBuffer->Release();
	if (IndexBuffer) IndexBuffer->Release();
	if (VertexLayout) VertexLayout->Release();
	if (FX) FX->Release();
	if (RenderTargetView) RenderTargetView->Release();
	if (SwapChain) SwapChain->Release();
	if (d3dDevice) d3dDevice->Release();
	if (DiffuseMapResourceView) DiffuseMapResourceView->Release();
	DIKeyboard->Unacquire();
	DIMouse->Unacquire();
	DirectInput->Release();

	return true;
}
Beispiel #18
0
Engine::Input::Input(const HWND &hWnd, HINSTANCE hInstance)
{
	LPDIRECTINPUT8 directInputObject;

	DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&directInputObject, NULL);
	directInputObject->CreateDevice(GUID_SysKeyboard, &_pKeyBoard, NULL);
	directInputObject->CreateDevice(GUID_SysMouse, &_pMouse, NULL);

	_pKeyBoard->SetDataFormat(&c_dfDIKeyboard);
	_pKeyBoard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);

	_pMouse->SetDataFormat(&c_dfDIMouse);
	_pMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);

	_pKeyBoard->Acquire();
	_pMouse->Acquire();
	directInputObject->Release();

	ZeroMemory(_keyState, sizeof(_keyState));
	ZeroMemory(&_mouseState, sizeof(_mouseState));
}
int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// kill the reactor
Destroy_Bitmap(&reactor);

// kill skelaton
Destroy_BOB(&skelaton);

// release keyboard
lpdikey->Unacquire();
lpdikey->Release();
lpdi->Release();

// shutdonw directdraw
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
Beispiel #20
0
// release our DirectInput effects and devices, our DirectInput handle, and then unload dinput library
void FreeDirectInput ()
{
	int i;
	// release effects
	for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i )
		ReleaseEffect( g_apdiEffect[i] );
	ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) );

	// release FF devices
	for( i = 0; i << ARRAYSIZE(g_apFFDevice); ++i )
		ReleaseDevice( g_apFFDevice[i] );
	ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) );

	// release normal devices
	for( i = 0; i < g_nDevices; i++ )
		ReleaseDevice( g_devList[i].didHandle );
	ZeroMemory( g_devList, sizeof(g_devList) );
	g_nDevices = 0;

	// release mouse device
	ReleaseDevice( g_sysMouse.didHandle );
	ZeroMemory( &g_sysMouse, sizeof(g_sysMouse) );

    // Release any DirectInput handles.
	if( g_pDIHandle != NULL )
	{
		g_pDIHandle->Release();
		g_pDIHandle = NULL;
	}
	// Unload the library.
	if( g_hDirectInputDLL != NULL )
	{
		FreeLibrary( g_hDirectInputDLL );
		g_hDirectInputDLL = NULL;
	}
	return;
}
Beispiel #21
0
void free_input(LPDIRECTINPUT8 lpdi)
{
	lpdi->Release();
}
Beispiel #22
0
    void shutdown()
    {
	directInput->Release();
	mouseDevice->Release();
	keyboardDevice->Release();
    }
Beispiel #23
0
/*** DLLメイン関数 ***/
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    CHAR path[512],file[128],ext[64];
    switch(ul_reason_for_call) {
    case DLL_PROCESS_DETACH:
        GetModuleFileName(NULL, path,MAX_PATH-1);
        DEBUG_OUT("AsukaLibは Module %s から切り離されました\n",path);
        DestroyMenu(MainPopup);
        if(D3D8inst) FreeLibrary(D3D8inst);
        if(DI8inst) FreeLibrary(DI8inst);
        if(DS8inst) FreeLibrary(DS8inst);
        if(MainDI8) MainDI8->Release();// DirectInputは明示的に生成したからRelease
        if(MainDS8) MainDS8->Release();//
        if(bIniLoaded) SaveIniData(&Ini);
        ReleaseSoundBufferChain();
        return TRUE;
    case DLL_PROCESS_ATTACH:
        bIniLoaded = FALSE;
        GetModuleFileName(NULL, path,MAX_PATH-1);
        DEBUG_OUT("AsukaLibは Module %s から呼び出されました\n",path);
        hDLL = hModule;
        break;
    default:
        return TRUE;
    }



    GetModuleFileName(NULL,path,MAX_PATH-1);
    _splitpath_s(path,NULL,0,NULL,0,file,ARRAYSIZE(file),ext,ARRAYSIZE(ext));
    strcat_s(file,ARRAYSIZE(file),ext);
    if(lstrcmpi(file,TARGET_EXE) != 0) {
        DEBUG_OUT("%sによるDLL呼び出しなのでフック中止(Target: %s)\n",file,TARGET_EXE);
        return TRUE;
    }

    LoadIniData(&Ini);
    bIniLoaded = TRUE;

    // ポップアップメニューのロード
    MainPopup = LoadMenu((HINSTANCE)hModule,MAKEINTRESOURCE(ID_POPUPMENU));
    SubPopup = GetSubMenu(MainPopup,0);

    // Iniからデフォルト状態の復帰
    CheckMenuItem(SubPopup,IDM_MUTE_BGM,Ini.BGMMute?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_MUTE_SE,Ini.SEMute?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_LOCK_CONFIG,Ini.LockConfig?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDC_SAVEWINDOWSET,Ini.SaveWindowSettings?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_RESIZABLE,Ini.WindowResizable?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_HOLDASPECTRATIO,Ini.HoldAspectRatio?MF_CHECKED:MF_UNCHECKED);
    EnableMenuItem(SubPopup,IDM_HOLDASPECTRATIO,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);
    EnableMenuItem(SubPopup,IDM_SIZE_640,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);
    EnableMenuItem(SubPopup,IDM_SIZE_800,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);
    EnableMenuItem(SubPopup,IDM_SIZE_960,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);

    // Direct3Dをロード
    GetSystemDirectory(path,ARRAYSIZE(path));
    strcat_s(path,ARRAYSIZE(path),"\\d3d8.dll");
    D3D8inst = LoadLibrary(path);
    fpD3DCreate8 = (FuncPtrDirect3DCreate8)GetProcAddress(D3D8inst, "Direct3DCreate8");

    // DirectInput8をロード
    GetSystemDirectory(path,ARRAYSIZE(path));
    strcat_s(path,ARRAYSIZE(path),"\\dinput8.dll");
    DI8inst = LoadLibrary(path);
    fpDI8Create = (FuncPtrDirectInput8Create)GetProcAddress(DI8inst, "DirectInput8Create");

    // DirectSound8をロード
    GetSystemDirectory(path,ARRAYSIZE(path));
    strcat_s(path,ARRAYSIZE(path),"\\dsound.dll");
    DS8inst = LoadLibrary(path);
    fpDSCreate8 = (FuncPtrDirectSoundCreate8)GetProcAddress(DS8inst, "DirectSoundCreate8");

    return TRUE;
}
 ULONG _stdcall Release(void)
 {
     return RealInput->Release();
 }
void PsychHIDInitializeHIDStandardInterfaces(void)
{
    int i;
    HRESULT rc;
    HINSTANCE modulehandle = NULL;
    dinput = NULL;
    ndevices = 0;

    // Init x_dev array:
    for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) x_dev[i] = NULL;

    // Init keyboard queue arrays:
    memset(&psychHIDKbQueueFirstPress[0], 0, sizeof(psychHIDKbQueueFirstPress));
    memset(&psychHIDKbQueueFirstRelease[0], 0, sizeof(psychHIDKbQueueFirstRelease));
    memset(&psychHIDKbQueueLastPress[0], 0, sizeof(psychHIDKbQueueLastPress));
    memset(&psychHIDKbQueueLastRelease[0], 0, sizeof(psychHIDKbQueueLastRelease));
    memset(&psychHIDKbQueueActive[0], 0, sizeof(psychHIDKbQueueActive));
    memset(&psychHIDKbQueueScanKeys[0], 0, sizeof(psychHIDKbQueueScanKeys));

    // We need the module instance handle of ourselves, ie., the PsychHID mex file to
    // open a DirectInput-8 interface, so the OS can apply backwards compatibility fixes
    // specific to the way our mex file DLL was built. For this we need the name of the
    // mex file, which is dependent on Octave vs. Matlab and 32-Bit vs. 64-Bit:
#ifndef PTBOCTAVE3MEX
    // Matlab: 64-Bit or 32-Bit mex file?
#if defined(__LP64__) || defined(_M_IA64) || defined(_WIN64)
    // 64-Bit:
    modulehandle = GetModuleHandle("PsychHID.mexw64");
#else
    // 32-Bit:
    modulehandle = GetModuleHandle("PsychHID.mexw32");
#endif
#else
    // Octave: Same mex file file-extension for 32/64-Bit:
    modulehandle = GetModuleHandle("PsychHID.mex");
#endif

    // If this doesn't work, try with application module handle as fallback. This works usually on
    // Windows XP/Vista/7, but may fail catastrophically on Windows-8 and later:
    if (NULL == modulehandle) {
        printf("PsychHID-WARNING: Could not get module handle to PsychHID mex file. Did you rename it? Please don't do that!\n");
        printf("PsychHID-WARNING: Will try application module handle as fallback. This may end badly, e.g., with a crash. Cross your fingers!\n");
        modulehandle = GetModuleHandle(NULL);
    }

    if (NULL == modulehandle) PsychErrorExitMsg(PsychError_system, "PsychHID: FATAL ERROR: Couldn't get module handle to create interface to Microsoft DirectInput-8! Game over!");

    // Open a DirectInput-8 interface:
    rc = DirectInput8Create(modulehandle, DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&dinput, NULL);

    if (DI_OK != rc) {
        printf("PsychHID-ERROR: Error return from DirectInput8Create: %x\n", (int) rc);
        if (rc == DIERR_OLDDIRECTINPUTVERSION) printf("PsychHID-ERROR: You need to install a more recent version of DirectX -- at least DirectX-8.\n");
        PsychErrorExitMsg(PsychError_system, "PsychHID: FATAL ERROR: Couldn't create interface to Microsoft DirectInput-8! Game over!");
    }

    // Enumerate all DirectInput keyboard(-like) devices:
    rc = dinput->EnumDevices(DI8DEVCLASS_KEYBOARD, (LPDIENUMDEVICESCALLBACK) keyboardEnumCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_INCLUDEHIDDEN);
    if (DI_OK != rc) {
        printf("PsychHID-ERROR: Error return from DirectInput8 EnumDevices(): %x! Game over!\n", (int) rc);
        goto out;
    }

    // Enumerate all DirectInput mouse(-like) devices:
    rc = dinput->EnumDevices(DI8DEVCLASS_POINTER, (LPDIENUMDEVICESCALLBACK) keyboardEnumCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_INCLUDEHIDDEN);
    if (DI_OK != rc) {
        printf("PsychHID-ERROR: Error return from DirectInput8 EnumDevices(): %x! Game over!\n", (int) rc);
        goto out;
    }

    // Enumerate all DirectInput joystick/gamepad(-like) devices:
    rc = dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, (LPDIENUMDEVICESCALLBACK) keyboardEnumCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_INCLUDEHIDDEN);
    if (DI_OK != rc) {
        printf("PsychHID-ERROR: Error return from DirectInput8 EnumDevices(): %x! Game over!\n", (int) rc);
        goto out;
    }

    // Create keyboard queue mutex for later use:
    KbQueueThreadTerminate = FALSE;
    PsychInitMutex(&KbQueueMutex);
    PsychInitCondition(&KbQueueCondition, NULL);

    // Create event object for signalling device state changes:
    hEvent = CreateEvent(   NULL,	// default security attributes
                            FALSE,	// auto-reset event: This would need to be set TRUE for PsychBroadcastCondition() to work on Windows!
                            FALSE,	// initial state is nonsignaled
                            NULL	// no object name
                        );

    // Ready.
    return;

out:
    ndevices = 0;

    // Close our dedicated x-display connection and we are done:
    if (dinput) dinput->Release();
    dinput = NULL;

    PsychErrorExitMsg(PsychError_system, "PsychHID: FATAL ERROR: X Input extension version 2.0 or later not available! Game over!");
}