2011-12-16 123 views
2

我已阅读hackchinacodeproject示例,但似乎无法弄清楚如何刻录现有的.iso文件。上面的例子展示了如何从一个文件夹制作一个.iso然后刻录它。我希望能够直接刻录一个iso文件。IMAPI2如何刻录已创建的ISO

下面是一些代码:

IDiscRecorder2 discRecorder = new MsftDiscRecorder2(); 
string Burner = comboBox1.SelectedItem.ToString(); 

foreach (DrvProperties prop in drv_props) 
{ 
    if (prop.letter.Contains(Burner)) // letter contains the drive's Letter (E:, G: etc.) 
    { 
    discRecorder.InitializeDiscRecorder(prop.ID); // ID contains drive's uniqueID 
    } 

} 

IDiscFormat2Data discFormatData = new MsftDiscFormat2Data(); 
discFormatData.Recorder = discRecorder; 

IMAPI_MEDIA_PHYSICAL_TYPE mediaType = discFormatData.CurrentPhysicalMediaType; 
...... 
...... 

可能有人请帮我得到什么?可以说我有example.iso。我现在应该怎么做?我不明白。 (我在CodeProject示例的代码中使用了IMAPI2.interop)。

非常感谢

+0

请有人如何在MsftFileSystemImage对象中添加.iso文件我该怎么办? – sparky 2011-12-18 22:06:37

回答

3

嗯,我终于想通了,首先你需要包含以下命名空间:

using System.Runtime.InteropServices; 
using System.Runtime.InteropServices.ComTypes; 

为了能够使用的IStream。

然后,你需要从SHLWAPI.DLL导入SHCreateStreamOnFIle打开“读流”到ISO:

private const uint STGM_SHARE_DENY_WRITE = 0x00000020; 
    private const uint STGM_SHARE_DENY_NONE = 0x00000040; 
    private const uint STGM_READ = 0x00000000; 
    private const uint STGM_WRITE = 0x00000001; 
    private const uint STGM_READWRITE = 0x00000002; 

    [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false, EntryPoint = "SHCreateStreamOnFileW")] 
    static extern void SHCreateStreamOnFile(string fileName, uint mode, ref IStream stream); 

IStream stream = null; 
SHCreateStreamOnFile(path2iso, STGM_READ | STGM_SHARE_DENY_WRITE, ref stream); 

,最后我提供给discFormatData.Write()方法。

discFormatData.Write(stream); 

我希望它可以帮助别人。保重