Partager via


Reading Data from a Portable Device to an Application

banner art

An application's principal means of reading data is by using the Read method of the IWMDMStorageControl interface. The Read method takes four parameters.

The first parameter controls processing and content modes for the operation. The modes are combined using a bitwise OR. For definitions of these modes and an explanation of their use, see IWMDMStorageControl::Read. One processor mode and one content mode must be specified.

The second parameter is a pointer to the file name to which the content will be copied.

The last two parameters are used for the callback methods of the optional IWMDMOperation interface and IWMDMProgress interface. These two parameters can be NULL.

To read from a storage medium, use IWMDMEnumStorage::Next to access the proper storage medium, query for the IWMDMStorageControl interface, and call the Read method. The following example code shows the progression from the IWMDMDevice interface:

hr = pIDevice->EnumStorage(&pIEnumStorage);

if SUCCEEDED(hr)
{
    hr = pIEnumStorage->Next(ulNumStorage, &pIStorage, &ulNumFetched);
    if SUCCEEDED(hr) 
    {
        hr = pIStorage->QueryInterface(IID_IWMDMStorageControl, 
                                       (void**)&pIWMDMStorageControl);

        if SUCCEEDED(hr)
        {
            hr = pIWMDMStorageControl->Read(WMDM_MODE_BLOCK | 
                                                WMDM_CONTENT_FILE, 
                                            L"TargetFile.wma", 
                                            NULL, NULL);
            if (E_BUSY & hr)
                wprintf(L"Device Busy\n");
            if (WMDM_E_INTERFACEDEAD & hr)
                wprintf(L"File previously deleted.\n");
            if SUCCEEDED(hr)
                wprintf(L"Read Succeeded\n");
        }
    }
}

See Also