int InputManager::checkForNewXInputDevices()
{
	DWORD dwResult;  
	XINPUT_STATE state;
	int nrOfControllersAdded = 0;

	for(int i = nrOfXInputDevices_; i < XUSER_MAX_COUNT; i++)
	{	
		dwResult = 0;
		ZeroMemory(&state, sizeof(XINPUT_STATE));
		dwResult = XInputGetState(i, &state);

		if(dwResult == ERROR_SUCCESS)
		{
			GUID guid;
			ZeroMemory(&guid, sizeof(guid));
			InputDevice* device = new XInputDevice(nrOfXInputDevices_++, guid, "Xbox Controller (non DI)", devices_.size());
			nrOfControllersAdded++;
			devices_.push_back(device);

			SEND_EVENT(&Event_CreateInputDevice(device, device->getInputObjectArray()));
		}
	}

	return nrOfControllersAdded;
}
bool InputManager::addNewDevice(HWND hWindow, GUID instanceGUID, GUID productGUID, std::string name)
{
	bool deviceAdded = false;

	InputDevice* device;

	if(nrOfXInputDevices_ >= XUSER_MAX_COUNT || !isXInputDevice(&productGUID))
	{
		LPDIRECTINPUTDEVICE8 dInputDevice;
		HRESULT result = dInput_->CreateDevice(instanceGUID, &dInputDevice, NULL);
		if(FAILED(result))
			return false;

		DirectInputDevice* diDevice = new DirectInputDevice(dInputDevice, instanceGUID, name, devices_.size());
		if(diDevice->Init(hWindow))
		{
			devices_.push_back(diDevice);

			device = diDevice;

			deviceAdded = true;
		}
	}
	else
	{
		device = new XInputDevice(nrOfXInputDevices_++, instanceGUID, name, devices_.size());
		devices_.push_back(device);

		deviceAdded = true;
	}

	if(deviceAdded)
	{
		SEND_EVENT(&Event_CreateInputDevice(device, device->getInputObjectArray()));
	}

	return deviceAdded;
}