NeroCom with c# - what's wrong in my code?

vbimport

#1

:confused: Hi everboby

I try to use NeroCom in c# project to burn some file on CD. i handled events ant try to make it run but it’s not runing and events not accoure.

can someone tell me what wrong with my code ?

using System;
using System.IO;
using System.Collections;
using System.Threading;
using System.Drawing;
using System.Web;
using NEROLib;

class neroTest
{
private NeroClass neroClass;
private NeroDrives drives;
private INeroDrives drives1;
private NeroDrive drive;

private NeroFolder  folder; 
private NeroISOTrack isoTrack;

/**********************************************/

public neroTest()  // constructor
{
	neroClass   = new NeroClass();
	isoTrack = new NeroISOTrackClass();
	folder   = new NeroFolderClass();
}

/**********************************************/
/** methods for events **/
private void OnDoneBurn(ref NERO_BURN_ERROR statusCode)
{
	if(statusCode != NERO_BURN_ERROR.NERO_BURN_OK)
	{
		Console.WriteLine("bad");
	}
	else
	{
		Console.WriteLine("OK");
	}
}

private void OnProgress(ref int ProgressInPercent, ref bool Abort)
{
	Console.WriteLine("OnProgress");
}

private void nDrive_OnDoneWaitForMedia(ref bool Success)
{            
	Console.WriteLine("nDrive_OnDoneWaitForMedia: ");
}
private void nDrive_OnAddLogLine(ref NERO_TEXT_TYPE TextType, ref string Text)
{
	Console.WriteLine("nDrive_OnAddLogLine");
}

private void nDrive_OnSetPhase(ref string Text)
{
	Console.WriteLine("nDrive_OnSetPhase " );
}		

private void nDrive_OnAborted(ref bool Abort)
{
	Console.WriteLine("nDrive_OnAborted" );          
}

private void nDrive_OnDoneCDInfo(NeroCDInfo pCDInfo)
{
	Console.WriteLine("nDrive_OnDoneCDInfo: ");
}

private void nDrive_OnDoneEstimateTrackSize(bool bOk, int BlockSize)
{
	Console.WriteLine("nDrive_OnDoneEstimateTrackSize: ");       
}

private void nDrive_OnDoneImport(ref bool Ok, ref NeroFolder Folder, ref NeroCDStamp CDStamp)
{
	Console.WriteLine("nDrive_OnDoneImport: ");
}

private void OnFileSelImage(ref string target)
{              
	Console.WriteLine("OnFileSelImage: ");
}

private void nClass_OnMegaFatal()
{
	Console.WriteLine("nClass_OnMegaFatal: " + "A mega fatal error has occurred.");
}

private void nClass_OnNonEmptyCDRW(ref NERO_RESPONSE Response)
{
	Console.WriteLine("nClass_OnNonEmptyCDRW: NERO_RETURN_EXIT");
}

private void nClass_OnWaitCD(ref NERO_WAITCD_TYPE WaitCD, ref string WaitCDLocalizedText)
{
	Console.WriteLine("nClass_OnWaitCD: " + WaitCDLocalizedText);
}

private void nClass_OnWaitCDMediaInfo(ref NERO_MEDIA_TYPE LastDetectedMedia, ref string LastDetectedMediaName, ref NERO_MEDIA_TYPE RequestedMedia, ref string RequestedMediaName)
{
	Console.WriteLine("nClass_OnWaitCDMediaInfo: Waiting for a particular media type: " + RequestedMediaName);
}

private void nClass_OnWaitCDReminder()
{
	Console.WriteLine("nClass_OnWaitCDReminder: Waiting for CD");
}

private void nClass_OnWaitCDDone()
{
	Console.WriteLine("nClass_OnWaitCDDone");
}

private void nClass_OnDriveStatusChanged(int hostID, int targetID, NERO_DRIVECHANGE_RESULT driveStatus)
{
	Console.WriteLine("nClass_OnDriveStatusChanged: hostID:" + hostID + " targetID:" + targetID + " " + driveStatus);
}
/**********************************************/

public void burn()
{
	// deff
	NeroFileClass file;
	
	// init
	file     = new NeroFileClass();
	isoTrack.Name = "TestTrack";
	isoTrack.RootFolder = folder; 

	// events init
	drive.OnDoneBurn += new _INeroDriveEvents_OnDoneBurnEventHandler(OnDoneBurn);
	drive.OnProgress += new _INeroDriveEvents_OnProgressEventHandler(OnProgress);
	drive.OnDoneWaitForMedia += new _INeroDriveEvents_OnDoneWaitForMediaEventHandler(nDrive_OnDoneWaitForMedia);
	drive.OnAddLogLine += new _INeroDriveEvents_OnAddLogLineEventHandler(nDrive_OnAddLogLine);
	drive.OnSetPhase += new _INeroDriveEvents_OnSetPhaseEventHandler(nDrive_OnSetPhase);
	drive.OnAborted += new _INeroDriveEvents_OnAbortedEventHandler(nDrive_OnAborted);
	drive.OnDoneCDInfo +=new _INeroDriveEvents_OnDoneCDInfoEventHandler(nDrive_OnDoneCDInfo);
//	drive.OnDoneEstimateTrackSize +=new _INeroDriveEvents_OnDoneEstimateTrackSizeEventHandler(nDrive_OnDoneEstimateTrackSize);
	drive.OnDoneImport += new _INeroDriveEvents_OnDoneImportEventHandler(nDrive_OnDoneImport);
        
	neroClass.OnFileSelImage += new _INeroEvents_OnFileSelImageEventHandler(OnFileSelImage);
	neroClass.OnMegaFatal += new _INeroEvents_OnMegaFatalEventHandler(nClass_OnMegaFatal);
	neroClass.OnNonEmptyCDRW += new _INeroEvents_OnNonEmptyCDRWEventHandler(nClass_OnNonEmptyCDRW);
	neroClass.OnWaitCD += new _INeroEvents_OnWaitCDEventHandler(nClass_OnWaitCD);
	neroClass.OnWaitCDMediaInfo += new _INeroEvents_OnWaitCDMediaInfoEventHandler(nClass_OnWaitCDMediaInfo);
	neroClass.OnWaitCDReminder += new _INeroEvents_OnWaitCDReminderEventHandler(nClass_OnWaitCDReminder);
	neroClass.OnWaitCDDone += new _INeroEvents_OnWaitCDDoneEventHandler(nClass_OnWaitCDDone);
	neroClass.OnDriveStatusChanged +=new _INeroEvents_OnDriveStatusChangedEventHandler(nClass_OnDriveStatusChanged);

	// exec
	folder.Files.Add(file);
	file.Name = "music.mp3.txt";
	file.SourceFilePath = @"D:\Yossi\music.txt";

	isoTrack.BurnOptions = (NEROLib.NERO_BURN_OPTIONS)((int)NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_CREATE_ISO_FS +
		                   (int)NEROLib.NERO_BURN_OPTIONS.NERO_BURN_OPTION_USE_JOLIET);

	drive.BurnIsoAudioCD("", "", false, isoTrack, null, null,
		                 NEROLib.NERO_BURN_FLAGS.NERO_BURN_FLAG_WRITE, 3,
		                 NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CD);
}

/**********************************************/

public void getDrives()
{
	string str;
	
	drives = neroClass.GetDrives(NEROLib.NERO_MEDIA_TYPE.NERO_MEDIA_CDRW);
	foreach(NeroDrive drive1 in drives)
	{
		str = drive1.DriveLetter;
		if(drive1.DriveLetter == "e")
		{
			drive = drive1;
	  	//    Console.WriteLine(drive.DeviceName);
	            //    Console.WriteLine(drive.DevType);
		}
	}

}

}

/**********************************************/

class TsstClass
{
public static void Main()
{
string p22;
neroTest neroObj;
neroObj = new neroTest();
neroObj.getDrives();
neroObj.burn();
}
}


#2

Could you be more spcific.
At first look your code seems ok.
Do you get any errors?
Does your burning proces start?
anything


#3

hello “gapilazo”

I get no errors and burning process not starting.

actually - it’s doing nothing

thank you for trying help


#4

I tested your code.
at the end put thred.sleep(100000)
and you will se theat all events fire like creazy.
all so drive.onAbord();
all so burn proces is started.

Did not have time to figure it out whay but it my help you

I think maybe something is wrong all so with declering drive_onDoneCDInfo()
but i am not shore

You shold maybe try to make windows application not consol it is easyer

Sory for my mistakes in english i am from Slovenija


#5

hello “gapilazo”

thank you - it’s working.

I’m sure that it will work in windows application without a need of sleep method

about your English - it’s o.k . I have sometimes problem with my English too.


#6

I am using Nero7.2 and I uses neroClass.GetDrives from my .Net code and doing some operation with Nero. Now thought of migarting to Nero9 and the Nero9 doesnt have NeroSDK.

Do any one has solution for this?