Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

CM_Request_Device_Eject (setupapi)
 
.
Summary
TODO - a short description

C# Signature:

    [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
    static extern int CM_Request_Device_Eject(UInt32 devinst, out PNP_VETO_TYPE pVetoType, System.Text.StringBuilder pszVetoName, int ulNameLength, int ulFlags);

VB Signature:

Declare Function CM_Request_Device_Eject Lib "setupapi.dll" (TODO) As TODO

User-Defined Types:

    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
    }

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

    CM_Query_And_Remove_SubTree has the same signature.
    CM_Request_Device_Eject_NoUi also can be used to eject a device. It has the same signature too.

    This is not the correct signature for 64-bit Windows...

Tips & Tricks:

Please add some!

Sample Code:

    // 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));
    }

Sample Code:

       public string Eject(bool allowUI)
       {
       if (!allowUI)
       {

           CM_Request_Device_Eject_NoUi((int)USBData.DevInst, IntPtr.Zero, null, 0, 0); // USBData, a SP_DEVINFO_DATA structure.
       }
       else
       {
           StringBuilder sb = new StringBuilder(1024);

           PNP_VETO_TYPE veto; // PNP_VETO_TYPE enumeration is used to identify the reason for rejection
           int hr = CM_Request_Device_Eject((int)USBData.DevInst, out veto, sb, sb.Capacity, 0);

           if (hr != 0)
           throw new Win32Exception(hr);
           if (veto != PNP_VETO_TYPE.Ok)
           return veto.ToString();
       }
       return null;
       }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions