Share via


Sending the File to the Device

banner art

After the file has been transcoded if necessary, and all metadata including the format has been set, your application can send the file to the device. In order to do so, you must first get an IWMDMStorageControl interface (or a later version) for a target location on the device. The Insert flags specify whether the new storage should be a sibling or child of the target. Once you have gotten the target, you can call IWMDMStorageControl::Insert, IWMDMStorageControl2::Insert2, or IWMDMStorageControl3::Insert3 to transfer the file. The application can handle reading the file data itself by implementing IWMDMOperation, or it can allow the Insert method to read and transfer the file automatically by not providing a pointer to an application-implemented IWMDMOperation.

The following C++ code demonstrates calling Insert3 to write a file to a device. If the pOperation pointer passed to Insert3 is NULL, the file will be sent in one step; if this pointer is a valid interface pointer, Windows Media Device Manager will call your callback method to get data in blocks. For details on how to implement IWMDMOperation, see Handling File Transfers Manually.

// Set the flags for the operation
UINT flags = WMDM_MODE_BLOCK | // Synchronous call. 
    WMDM_STORAGECONTROL_INSERTINTO | // Insert it into the destination folder.
    WMDM_CONTENT_FILE | // We're inserting a file.
    WMDM_FILE_CREATE_OVERWRITE; // Overwrite existing files.
if (pOperation != NULL)
    flags |= WMDM_CONTENT_OPERATIONINTERFACE;

// Send the file and metadata.
hr = pStgCtl3->Insert3(
    flags,
    WMDM_FILE_ATTR_FOLDER, // The current storage is a folder.
    const_cast<WCHAR*>(pwszFileName), // Source file.
    L"My New File.wma",//NULL, // Destination file name.
    pOperation, // NULL to allow the SDK to read the file; 
                // non-NULL to present raw data bytes to the SDK.
    pProgress, // Interface to send simple progress notifications.
    pMetadata, // IWMDMMetaData interface previously created and filled.
    NULL, 
    &pNewStorage); // Out: handle to the new storage, if the method succeeds.

See Also