dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.75k stars 190 forks source link

Interface not supported Exception while using the set operaiton in IMAPI #441

Closed BluerGost closed 3 months ago

BluerGost commented 4 months ago

I have attached the code I am using below. But during the [ iFileSystemImage.MultisessionInterfaces = iDiscFormat2Data.MultisessionInterfaces;] statement the code throws exception [Interface not supported]. Other properties also throw the same error during the [set].

public MediaInformation DetectMedia(IDiscRecorder2 discRecorder)
{
    MsftFileSystemImage fileSystemImage = new MsftFileSystemImage();
    MsftDiscFormat2Data discFormatData  = new MsftDiscFormat2Data();

    try
    {
        var iFileSystemImage = fileSystemImage as IFileSystemImage;
        var iDiscFormat2Data = discFormatData as IDiscFormat2Data;

        if (iFileSystemImage == null) 
        {
            Console.WriteLine($"Could not cast to IFileSystemImage");
            return null;
        } 

        if (iDiscFormat2Data == null) 
        {
            Console.WriteLine($"Could not cast to IDiscFormat2Data");
            return null;
        }

        if (!iDiscFormat2Data.IsCurrentMediaSupported(discRecorder))
        {
            Console.WriteLine("Current media is not supported");
            return null;
        }

        var mediaInformation = new MediaInformation();

        // Get the media type in the recorder
        iDiscFormat2Data.Recorder = discRecorder;
        var mediaType = (iDiscFormat2Data).CurrentPhysicalMediaType;
        var mediaTypeString = GetMediaTypeString(mediaType);
        mediaInformation.MediaType = mediaTypeString;
        Console.WriteLine($"Media Type : 「{mediaTypeString}」");

        // Create a file system and select media type
        iFileSystemImage.ChooseImageDefaultsForMediaType(mediaType);

        // See if there are other recored sessions on the disc
        if (!iDiscFormat2Data.MediaHeuristicallyBlank)
        {
            iFileSystemImage.MultisessionInterfaces = iDiscFormat2Data.MultisessionInterfaces;
            iFileSystemImage.ImportFileSystem();
        }

        var fileMediaBlocks = iFileSystemImage.FreeMediaBlocks;
        var totalDiskSize = 2048 * fileMediaBlocks;
        mediaInformation.TotalDiskSize = totalDiskSize;
        Console.WriteLine($"Total Disk Size : 「{totalDiskSize}」");

        return mediaInformation;
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
        return null;
    }
    finally
    {
        if (fileSystemImage != null)
        {
            Marshal.ReleaseComObject(fileSystemImage);
        }

        if (discFormatData != null)
        {
            Marshal.ReleaseComObject(discFormatData);
        }
    }
}
dahall commented 3 months ago

I think I've found the issue with setting IFileSystemImage.MultisessionInterfaces. Which other properties are failing settting?

dahall commented 3 months ago

Fixed for 4.0 build. Release coming soon.