Microsoft KB Archive/831734

= How to disable media change notification messages on a class device timer =

Article ID: 831734

Article Last Modified on 2/1/2007

-

APPLIES TO


 * Microsoft Windows Server 2003, Standard Edition (32-bit x86)
 * Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
 * Microsoft Windows XP Home Edition
 * Microsoft Windows XP Professional

-





SYMPTOMS
When a media changer moves media between storage and usage locations, the media changer incorrectly receives one media change notification message per second on a Microsoft Windows Server 2003-based computer or on a Microsoft Windows XP-based computer.



CAUSE
This issue occurs because, by default, the media change notification functionality is enabled in both Windows Server 2003 and Windows XP.



RESOLUTION
To resolve this issue, disable the media change notification messages. To do this, call the DeviceIOControl function by using the following parameters: BOOL DeviceIoControl( (HANDLE) hDevice,            // handle to device  IOCTL_STORAGE_MCN_CONTROL,   // dwIoControlCode  (LPVOID) lpInBuffer,         // input buffer  (DWORD) nInBufferSize,       // size of input buffer  NULL,                        // lpOutBuffer  0,                           // nOutBufferSize  (LPDWORD) lpBytesReturned,   // number of bytes returned  (LPOVERLAPPED) lpOverlapped  // OVERLAPPED structure );

Parameters

 * hDevice

[in] A handle to the device. Autoplay must be enabled on this device. To obtain a device handle, call the CreateFile function. Files must be opened with the FILE_READ_ATTRIBUTES access right. They must not be opened with read or with write access.
 * dwIoControlCode

[in] A control code for the operation. Use IOCTL_STORAGE_MCN_CONTROL for this operation.
 * lpInBuffer

[in] A pointer to a Boolean value. If this value is TRUE, media change detection is disabled. Otherwise, media change detection is enabled.
 * nInBufferSize

[in] The size of the input buffer, in bytes.
 * lpOutBuffer

A parameter that is not used with this operation; set to NULL.
 * nOutBufferSize

A parameter that is not used with this operation; set to 0 (zero).
 * lpBytesReturned

[out] The pointer to a variable that receives the size of the data that is stored in the output buffer, in bytes.

If the lpOverlapped parameter is NULL, the lpBytesReturned parameter cannot be NULL. Even when an operation returns no output data and the lpOutBuffer parameter is NULL, the DeviceIoControl function uses the lpBytesReturned parameter. In this scenario, the value of the lpBytesReturned parameter is meaningless.

If the lpOverlapped parameter is not NULL, the lpBytesReturned parameter may be NULL. If this parameter is not NULL and the operation returns data, the lpBytesReturned parameter is meaningless until the overlapped operation is completed. To retrieve the number of bytes that are returned, call the GetOverlappedResult method. If the hDevice handle is associated with an I/O completion port, you can retrieve the number of bytes that are returned by calling the GetQueuedCompletionStatus function.
 * lpOverlapped

[in] A pointer to an OVERLAPPED structure.

If the hDevice parameter was opened without specifying FILE_FLAG_OVERLAPPED, the lpOverlapped parameter is ignored.

If the hDevice parameter was opened by using the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, the lpOverlapped parameter must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.

For overlapped operations, the DeviceIoControl function returns immediately, and the event object is signaled when the operation is completed. Otherwise, the function does not return until the operation is completed or until an error occurs.

Note If the operation is successful, the DeviceIoControl function returns a nonzero value. If the operation is not successful, the DeviceIoControl function returns 0 (zero). To obtain extended error information, call the GetLastError function.

Note The &quot;[in]&quot; reference at the beginning of some of these parameter explanations indicates an input parameter: The caller must provide the data. The &quot;[out]&quot; reference indicates an output parameter: The caller receives the data when the call is returned.

