Я пытаюсь создать программу тестирования командной строки на C ++, которая выполняет обратную связь по усилию:
hWnd = CreateWindowExA(0L,
"Message", // name of window class
"x360ce", // title-bar std::string
WS_TILED, // normal window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
CW_USEDEFAULT, // default width
CW_USEDEFAULT, // default height
HWND_MESSAGE, // message-only window
NULL, // no class menu
GetModuleHandle(NULL), // handle to application instance
NULL); // no window-creation data
// to a IDirectInput interface we can use.
if (FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_lpDInput, NULL)))
{
return hr;
}
// Look for a force feedback device we can use
if (FAILED(hr = g_lpDInput->EnumDevices(DI8DEVCLASS_GAMECTRL,
EnumJoy, NULL,
DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK)))
{
return hr;
}
if (NULL == g_lpDIDeviceJoystick)
{
MessageBox(hWnd, _T("Force feedback device not found. ")
_T("The sample will now exit."),
_T("FFConst"), MB_ICONERROR | MB_OK);
DestroyWindow(hWnd);
return S_OK;
}
// Set the data format to "simple joystick" - a predefined data format. A
// data format specifies which controls on a device we are interested in,
// and how they should be reported.
//
// This tells DirectInput that we will be passing a DIJOYSTATE structure to
// IDirectInputDevice8::GetDeviceState(). Even though we won't actually do
// it in this sample. But setting the data format is important so that the
// DIJOFS_* values work properly.
if (FAILED(hr = g_lpDIDeviceJoystick->SetDataFormat(&c_dfDIJoystick)))
return hr;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
// Exclusive access is required in order to perform force feedback.
if (FAILED(hr = g_lpDIDeviceJoystick->SetCooperativeLevel(hWnd,DISCL_EXCLUSIVE | DISCL_FOREGROUND)))
{
return hr;
}
// Since we will be playing force feedback effects, we should disable the
// auto-centering spring.
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = DIPROPAUTOCENTER_OFF;
if (FAILED(hr = g_lpDIDeviceJoystick->SetProperty(DIPROP_AUTOCENTER, &dipdw.diph)))
return hr;
// Enumerate and count the axes of the joystick
if (FAILED(hr = g_lpDIDeviceJoystick->EnumObjects(EnumAxesCallback, (VOID*)&g_dwNumForceFeedbackAxis, DIDFT_AXIS)))
return hr;
// This simple sample only supports one or two axis joysticks
if (g_dwNumForceFeedbackAxis > 2)
g_dwNumForceFeedbackAxis = 2;
if (FAILED(hr = g_lpDIDeviceJoystick->Acquire()))
return hr;
но после «Acquire» я получаю отказ в доступе, это происходит, потому что при использовании доступа DISCL_EXCLUSIVE мне нужен реальный дескриптор окна, у которого есть фокус, но я использую приложение командной строки, а не приложение windows.
Есть способ решить?
Спасибо!