将文件发送到设备

如有必要,对文件进行转码并设置所有元数据(包括格式)后,应用程序可以将文件发送到设备。 为此,必须先获取 IWMDMStorageControl 接口, (或更高版本) 设备上的目标位置。 Insert 标志指定新存储应是目标的同级存储还是子存储。 获取目标后,可以调用 IWMDMStorageControl::InsertIWMDMStorageControl2::Insert2IWMDMStorageControl3::Insert3 来传输文件。 应用程序可以通过实现 IWMDMOperation 来处理文件数据本身的读取,也可以允许 Insert 方法通过不提供指向应用程序实现的 IWMDMOperation 的指针来自动读取和传输文件。

以下 C++ 代码演示如何调用 Insert3 将文件写入设备。 如果传递给 Insert3的 pOperation 指针为 NULL,则将在一个步骤中发送文件;如果此指针是有效的接口指针,则 Windows Media 设备管理器 将调用回调方法来获取块中的数据。 有关如何实现 IWMDMOperation 的详细信息,请参阅 手动处理文件传输

// 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.

将文件写入设备