/// <Summary>Creates a libusbK handle for the device specified by a file handle.</Summary> public UsbK(IntPtr DeviceHandle, KUSB_DRVID driverID) { bool success = AllKFunctions.LibK_LoadDriverAPI(out driverAPI, (int) driverID); if (!success) throw new Exception(string.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", GetType().Name, Marshal.GetLastWin32Error())); success = driverAPI.Initialize(DeviceHandle, out mHandleStruct); if (!success) throw new Exception(string.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", GetType().Name, Marshal.GetLastWin32Error())); Debug.Print("{0} Init: handle 0x{1:X16}", GetType().Name, mHandleStruct.Pointer.ToInt64()); }
/// <Summary>Creates a libusbK handle for the device specified by a file handle.</Summary> public UsbK(IntPtr DeviceHandle, KUSB_DRVID driverID) { if (!Functions.LibK_LoadDriverAPI(out driverAPI, (int) driverID)) { throw new Exception(GetType().Name + " failed loading Driver API. ErrorCode=" + Marshal.GetLastWin32Error().ToString("X")); } RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { bool success = driverAPI.Initialize(DeviceHandle, out handle); if (!success || handle.IsInvalid || handle.IsClosed) { handle.SetHandleAsInvalid(); int errorCode = Marshal.GetLastWin32Error(); throw new Exception(GetType().Name + " failed. ErrorCode=" + errorCode.ToString("X")); } } }