BetterExplorer.UsbEject.Native.CM_Request_Device_Eject_NoUi C# (CSharp) Method

CM_Request_Device_Eject_NoUi() private method

private CM_Request_Device_Eject_NoUi ( int dnDevInst, IntPtr pVetoType, StringBuilder pszVetoName, int ulNameLength, int ulFlags ) : int
dnDevInst int
pVetoType System.IntPtr
pszVetoName StringBuilder
ulNameLength int
ulFlags int
return int
        internal static extern int CM_Request_Device_Eject_NoUi(
            int dnDevInst,
            IntPtr pVetoType,
            StringBuilder pszVetoName,
            int ulNameLength,
            int ulFlags
            );

Usage Example

Beispiel #1
0
        /// <summary>
        /// Ejects the device.
        /// </summary>
        /// <param name="allowUI">Pass true to allow the Windows shell to display any related UI element, false otherwise.</param>
        /// <returns>null if no error occured, otherwise a contextual text.</returns>
        public Native.PNP_VETO_TYPE Eject(bool allowUI)
        {
            foreach (Device device in RemovableDevices)
            {
                if (allowUI)
                {
                    Native.CM_Request_Device_Eject_NoUi(device.InstanceHandle, IntPtr.Zero, null, 0, 0);
                    // don't handle errors, there should be a UI for this
                }
                else
                {
                    StringBuilder sb = new StringBuilder(1024);

                    Native.PNP_VETO_TYPE veto;
                    int hr = Native.CM_Request_Device_Eject(device.InstanceHandle, out veto, sb, sb.Capacity, 0);
                    //if (hr != 0)
                    //    throw new Win32Exception(hr);

                    return(veto);
                }
            }
            return(Native.PNP_VETO_TYPE.TypeUnknown);
        }