Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.060 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: JvHidControllerClass unter Windows 10 1809

  Alt 1. Mär 2019, 12:23
Ah, der Workaround lässt sich einfach umsetzen.

Füge die Unit JvHidControllerClass zu deinen Projekt hinzu und ersetze die ursprüngliche TJvHidDevice.CtlCreate mit folgenden Workaround:

Delphi-Quellcode:
constructor TJvHidDevice.CtlCreate(const APnPInfo: TJvHidPnPInfo; const Controller: TJvHidDeviceController);
var
  LDevicePath: string; // für Workaround
begin
  inherited Create;

  // initialize private data
  FMyController := Controller;
  FIsPluggedIn := True;
  FIsCheckedOut := False;
  FIsEnumerated := False;
  FHidOverlappedRead := INVALID_HANDLE_VALUE;
  FHidOverlappedWrite := INVALID_HANDLE_VALUE;
  FVendorName := '';
  FProductName := '';
  FPreparsedData := nil;
  SetLength(FPhysicalDescriptor, 0);
  FSerialNumber := '';
  FLanguageStrings := TStringList.Create;
  FNumInputBuffers := 0;
  FNumOverlappedBuffers := 0;
  SetLength(FLinkCollection, 0);
  FMaxDataListLength := 0;
  FMaxUsageListLength := 0;
  FMaxButtonListLength := 0;
  FReportTypeParam := HIDP_Input;
  FPollingDelayTime := Controller.DevPollingDelayTime;
  FThreadSleepTime := Controller.DevThreadSleepTime;
  FUsagePageParam := 0;
  FLinkCollectionParam := 0;
  FUsageParam := 0;
  FDataThread := nil;
  OnData := Controller.OnDeviceData;
  OnUnplug := Controller.OnDeviceUnplug;

  // https://stackoverflow.com/questions/53761417/createfile-over-usb-hid-device-fails-with-access-denied-5-since-windows-10-180
  // Beginn des Workarounds
  if APnPInfo.DevicePath.EndsWith('\kbd') then
  begin
    LDevicePath := APnPInfo.DevicePath.Remove(APnPInfo.DevicePath.IndexOf('\kbd'));
  end else
    LDevicePath := APnPInfo.DevicePath;
  // Ende des Workarounds

  FHidFileHandle := CreateFile(PChar(LDevicePath), GENERIC_READ or GENERIC_WRITE,
    FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
  FHasReadWriteAccess := HidFileHandle <> INVALID_HANDLE_VALUE;
  // Win2000 hack
  if not HasReadWriteAccess then
    FHidFileHandle := CreateFile(PChar(LDevicePath), 0,
      FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
  if HidFileHandle <> INVALID_HANDLE_VALUE then
  begin
    FAttributes.Size := SizeOf(THIDDAttributes);
    if not HidD_GetAttributes(HidFileHandle, FAttributes) then
      raise EControllerError.CreateRes(@RsEDeviceCannotBeIdentified);
  end
  else
    raise EControllerError.CreateRes(@RsEDeviceCannotBeOpened);
  FPnPInfo := APnPInfo;
  // the file is closed to stop using up resources
  CloseFile;
end;
Mit der Änderung könntest du natürlich auch die JCL und JVCL neu bauen. Dann spart man sich das Hinzufügen zum Projekt.
  Mit Zitat antworten Zitat