SwDeviceClose function

Closes the software device handle. When the handle is closed, PnP will initiate the process of removing the device.


void SwDeviceClose(



The HSWDEVICE handle to close.

Return value



After SwDeviceClose returns, the operating system is guaranteed to not call the SW_DEVICE_CREATE_CALLBACK callback function, and any calls to Software Device API functions that were in progress are guaranteed to have completed.

You can call SwDeviceClose at any time even if the callback function hasn't been called yet.

In Windows 8, you can't call SwDeviceClose inside the SW_DEVICE_CREATE_CALLBACK callback function. Doing so will cause a deadlock. Be careful of releasing a ref counted object that will call SwDeviceClose when its destructor runs. In Windows 8.1, this restriction is lifted, and you can call SwDeviceClose inside the callback function.

By calling SwDeviceClose, you initiate the process of removing a device from PnP. The call to SwDeviceClose returns before this removal is complete. But you can safely call SwDeviceCreate immediately after SwDeviceClose. The new create will be queued until the previous removal processing completes, and then the device will be re-created.

PnP removal makes the device "Not present." PnP removal of a device is the same us unplugging a USB device. All the persisted property state for the device remains in memory.


Minimum supported client Windows 8
Minimum supported server Windows Server 2012
Target Platform Universal
Header swdevice.h
Library Swdevice.lib; OneCoreUAP.lib on Windows 10
DLL Cfgmgr32.dll

See also