MCPcopy Create free account
hub / github.com/SFML/SFML / openDInput

Method openDInput

src/SFML/Window/Win32/JoystickImpl.cpp:515–825  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

513
514////////////////////////////////////////////////////////////
515bool JoystickImpl::openDInput(unsigned int index)
516{
517 // Initialize DirectInput members
518 m_device = nullptr;
519
520 m_axes.fill(-1);
521 m_buttons.fill(-1);
522
523 m_deviceCaps = {};
524 m_deviceCaps.dwSize = sizeof(DIDEVCAPS);
525 m_state = JoystickState();
526 m_buffered = false;
527
528 // Search for a joystick with the given index in the connected list
529 for (const JoystickRecord& record : joystickList)
530 {
531 if (record.index == index)
532 {
533 // Create device
534 HRESULT result = directInput->CreateDevice(record.guid, &m_device, nullptr);
535
536 if (FAILED(result))
537 {
538 err() << "Failed to create DirectInput device: " << result << std::endl;
539
540 return false;
541 }
542
543 // Get vendor and product id of the device
544 auto property = DIPROPDWORD();
545 property.diph.dwSize = sizeof(property);
546 property.diph.dwHeaderSize = sizeof(property.diph);
547 property.diph.dwHow = DIPH_DEVICE;
548
549 if (SUCCEEDED(m_device->GetProperty(DIPROP_VIDPID, &property.diph)))
550 {
551 m_identification.productId = HIWORD(property.dwData);
552 m_identification.vendorId = LOWORD(property.dwData);
553
554 // Check if device is already blacklisted
555 if (m_identification.productId && m_identification.vendorId)
556 {
557 for (const JoystickBlacklistEntry& blacklistEntry : joystickBlacklist)
558 {
559 if ((m_identification.productId == blacklistEntry.productId) &&
560 (m_identification.vendorId == blacklistEntry.vendorId))
561 {
562 // Device is blacklisted
563 m_device->Release();
564 m_device = nullptr;
565
566 return false;
567 }
568 }
569 }
570 }
571
572 // Get friendly product name of the device

Callers

nothing calls this directly

Calls 4

JoystickStateClass · 0.85
DIPROPDWORDClass · 0.85
DIPROPSTRINGClass · 0.85
toAnsiStringMethod · 0.80

Tested by

no test coverage detected