The IOCTL_STORAGE_CHECK_VERIFY DeviceIoControl operation determines whether a device's media is accessible; for example, whether the media is in the device.
BOOL DeviceIoControl(
(HANDLE) hDevice, // handle to device of interest
IOCTL_STORAGE_CHECK_VERIFY, // dwIoControlCode, control code of
// operation to perform
NULL, // lpInBuffer is not used; must be NULL
0, // nInBufferSize is not used; must be zero
NULL, // lpOutBuffer is not used; must be NULL
0, // nOutBufferSize is not used;
// must be zero
(LPDWORD) lpBytesReturned, // pointer to variable to receive
// output byte count
(LPOVERLAPPED) lpOverlapped // pointer to OVERLAPPED structure