How to write data?

Hi to all!!

I try to develop a simple application that burn data on CD/DVD, but I have a problem that I don't understand.

I attach the code. Thanks for all suggestions.

privatevoid btnMasterizza_Click(object sender,EventArgs e)

{

MsftFileSystemImageClass image =newMsftFileSystemImageClass();

image.Root.AddTree(@"C:\Users\Vista\Documents\Prova",false);

// Initialize a disc recorder

string recorderID =newMsftDiscMaster2Class()[0];

MsftDiscRecorder2Class recorder =newMsftDiscRecorder2Class();

recorder.InitializeDiscRecorder(recorderID);

// Prepare the DiscFormat2Data object

MsftDiscFormat2DataClass fmtObj =newMsftDiscFormat2DataClass();

fmtObj.Recorder = recorder;

fmtObj.SetWriteSpeed(4,true);

IMAPI2FS.IStream istm = image.CreateResultImage().ImageStream;

IMAPI2.IStream ff = (IMAPI2.IStream)istm;

// Write data

fmtObj.Write(ff);

}

[1697 byte] By [Salvus] at [2008-2-5]
# 1

Hello Salvus!

I'd be glad to help you as much as I can, but it would be helpful to know what error message you are receiving to help pinpoint the exact problem with your code.

From an initial code review (setting the nuances of C# code aside as I will assume they are correct for now :)), there appear to be two small "errors", one of which is fatal and one which is not.

The fatal error is that you did not set the ClientName property of the MsftDiscFormat2Data object. This will cause the burn to fail since it cannot properly acquire exclusive access, as CDROM.sys will reject the exclusive access request with no client name.

The non-fatal error is the call to SetWriteSpeed. This call will never really work as written, since the argument it takes is in 'sectors per second' and not the standard 'x-factor'. It will succeed and return a success code letting you know that the set succeeded but the speed the drive took is different from the one you set. If you wanted to really do '4x' as the speed, you can use the constants defined in imapi2.h (IMAPI_SECTORS_PER_SECOND_AT_1X_*) based on the media type (currently just CD vs DVD). To use these correctly, just multiply by the 'x-factor' you are looking for and use that as the requested speed...

If neither of those are what is causing the error you are seeing, please let me know the exact error and where it is coming from and I'll try and assist you more!

thanks,

Garrett Jacobson
SDE, Optical Platform Group

Garrett-MSFT at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Optical Platform Discussion...

Software Development for Windows Vista

Site Classified