[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
static extern int CM_Request_Device_Eject(IntPtr devinst, out PNP_VETO_TYPE pVetoType, System.Text.StringBuilder pszVetoName, int ulNameLength, int ulFlags);
Declare Function CM_Request_Device_Eject Lib "setupapi.dll" (TODO) As TODO
enum PNP_VETO_TYPE : int
{
PNP_VetoTypeUnknown = 0,
PNP_VetoLegacyDevice = 1,
PNP_VetoPendingClose = 2,
PNP_VetoWindowsApp = 3,
PNP_VetoWindowsService = 4,
PNP_VetoOutstandingOpen = 5,
PNP_VetoDevice = 6,
PNP_VetoDriver = 7,
PNP_VetoIllegalDeviceRequest = 8,
PNP_VetoInsufficientPower = 9,
PNP_VetoNonDisableable = 10,
PNP_VetoLegacyDriver = 11,
PNP_VetoInsufficientRights = 12
}
Do you know one? Please contribute it!
CM_Query_And_Remove_SubTree has the same signature.
Please add some!
// Assuming have IntPtr devinst already
//
// static readonly int CR_SUCCESS = 0x00000000; // cfgmgr32.h
// static readonly int DN_REMOVABLE = 0x00004000; // cfg.h
if (CR_SUCCESS == CM_Get_DevNode_Status(ref status, ref problem, devinst, 0) && (DN_REMOVABLE & status) > 0)
{
PNP_VETO_TYPE pnp_veto_type;
System.Text.StringBuilder sb = new System.Text.StringBuilder(255);
bool success = (CR_SUCCESS == CM_Request_Device_Eject(devinst, out pnp_veto_type, sb, sb.Capacity, 0));
}