/// <summary> /// Creates and initialize a <a href="http://libusb.sourceforge.net/api-1.0/index.html">Libusb-1.0</a> USB session handle. /// </summary> /// <remarks> /// <para>A <see cref="MonoUsbSessionHandle"/> instance must be created before calling any other <a href="http://libusb.sourceforge.net/api-1.0/index.html">Libusb-1.0 API</a> function.</para> /// </remarks> public MonoUsbSessionHandle() : base(IntPtr.Zero, true) { lock (sessionLOCK) { IntPtr pNewSession = IntPtr.Zero; try { mLastReturnCode = (MonoUsbError)MonoUsbApi.Init(ref pNewSession); } catch (DllNotFoundException dllNotFound) { if (LHelper.IsLinux) { throw new DllNotFoundException(DLL_NOT_FOUND_LINUX, dllNotFound); } else { throw new DllNotFoundException(DLL_NOT_FOUND_WINDOWS, dllNotFound); } } if ((int)mLastReturnCode < 0) { mLastReturnString = MonoUsbApi.StrError(mLastReturnCode); SetHandleAsInvalid(); } else { SetHandle(pNewSession); mSessionCount++; } } }
/// <summary> /// Creates and initialize a <a href="http://libusb.sourceforge.net/api-1.0/index.html">Libusb-1.0</a> USB session handle. /// </summary> /// <remarks> /// <para>A <see cref="MonoUsbSessionHandle"/> instance must be created before calling any other <a href="http://libusb.sourceforge.net/api-1.0/index.html">Libusb-1.0 API</a> function.</para> /// </remarks> public MonoUsbSessionHandle() : base(IntPtr.Zero, true) { lock (sessionLOCK) { IntPtr pNewSession = IntPtr.Zero; try { mLastReturnCode = (Error)MonoUsbApi.Init(ref pNewSession); } catch (DllNotFoundException dllNotFound) { if (Helper.IsLinux) { throw new DllNotFoundException(DLL_NOT_FOUND_LINUX, dllNotFound); } else { throw new DllNotFoundException(DLL_NOT_FOUND_WINDOWS, dllNotFound); } } if (mLastReturnCode != Error.Success) { throw new MonoUsbException(mLastReturnCode); } else { SetHandle(pNewSession); mSessionCount++; } } }