Share via


Handling File Transfers Manually

banner art

Your application can implement the IWMDMOperation interface to manage part of the reading or writing process. On a read from device, the implementation enables the application to receive blocks of raw data from a device file. On a write to device, it enables the application to send blocks of raw data to a file on the device.

In both read and write operations, the IWMDMOperation::TransferObjectData method passes the data between the computer and the device. To know the direction of the data transfer, your application must set a flag when Windows Media Device Manager calls BeginRead or BeginWrite. When the End method is called, the application should reset this flag.

  • **Note   **If the service provider and device properly implement IMDSPObject2, it will first call the application's IWMDMOperation3::TransferObjectDataOnClearChannel method, if implemented. This method is a more efficient way of transferring data. TransferObjectDataOnClearChannel is handled the same way as TransferObjectData, except that the data is never encrypted and has no MAC values to verify.

The following sections describe both the reading and the writing process, when your application implements IWMDMOperation.

Reading from a device

When reading a file from a device, Windows Media Device Manager calls the following IWMDMOperation methods in order:

  • BeginRead   Called to notify the application that a read from device is beginning.
  • TransferObjectData   Called one or more times. The processing of data is described in the following steps:
    1. TransferObjectData receives a buffer, pData, of size pdwSize bytes, filled with data, and a MAC to verify the incoming data.
    2. The application verifies the incoming parameters with the incoming data MAC.
    3. The application decrypts and read as much of the data in pData as it can, and modifies the returned value of pdwSize to indicate how many bytes were actually read.
    4. The application decrypts the data, using CSecureChannelClient::DecryptParam, and stores it or uses it, as needed.
    5. TransferObjectData returns S_OK.
    6. Windows Media Device Manager continues to call TransferObjectData until the application has read all the data from the file, or the application returns WMDM_E_USER_CANCELLED to cancel the operation (in which case the read is canceled, and Windows Media Device Manager calls End).
  • End   Called to notify the application that a read from device is ending.

Writing to a device

When writing a file to the device, Windows Media Device Manager calls the following IWMDMOperation methods in order:

  • GetObjectName   Called to allow the application to specify a name for the new storage. This method is only called if the application did not specify a name in the Insert method.
  • GetObjectAttributes   Called to allow the application to specify attributes for the new storage on the device.
  • BeginWrite   Called to notify that that a write to device is beginning.
  • GetObjectTotalSize   Called to retrieve the total size of the object being written to the device, to enable optimization of the transfer, and also to give Windows Media Device Manager an opportunity to cancel the transfer if the file is too large for the device.
  • TransferObjectData   Called one or more times. The processing of data is described in the following steps:
    1. TransferObjectData receives a pointer to a buffer of size pdwSize bytes.
    2. The application gets a block of data to send to the device, usually by reading data from a file, and fills the received buffer with up to pdwSize bytes. It should modify pdwSize (if necessary) to reflect how many bytes were added to the buffer.
    3. The application creates a MAC of all the method parameters.
    4. The application encrypts the data in the buffer, using CSecureChannelClient::EncryptParam.
    5. TransferObjectData returns S_OK to indicate that there is more data, or S_FALSE to indicate that there is no more data. If the application returns WMDM_E_USER_CANCELLED, the write operation is canceled and Windows Media Device Manager will call End.
    6. Windows Media Device Manager continues to call TransferObjectData as long as the application returns S_OK.
  • End   Called to notify that that a write to device is ending.

For a code example, see Encryption and Decryption.

See Also