Dvd Not Writing

Here I am Attaching My Code and Nero History Error. It is Not Writing to Dvd For Cd The Code is Ok. Just Verify and try to correct.


// Burn_Cd.cpp: implementation of the CBurn_Cd class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Cd_Write.h"
#include "Burn_Cd.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBurn_Cd::CBurn_Cd()
{
	m_NeroDeviceHandle = NULL;
	m_NeroDeviceInFos = NULL;
	m_pCDStamp = NULL;
	m_NeroCDInfo = NULL;
	Device_Ptr_Func=new CString;
	pcMedia=MEDIA_CD;
    NeroLoad();
	NeroAPIInit();

}

CBurn_Cd::~CBurn_Cd()
{
// Let the NeroAPI perform the required cleanup

	if (m_bNeroInitialized)
	{
		delete Device_Ptr_Func;
		NeroCloseDevice (m_NeroDeviceHandle);
		NeroFreeMem (m_NeroDeviceInFos);
		NeroFreeMem (m_NeroCDInfo);
		NeroFreeCDStamp (m_pCDStamp);
		NeroClearErrors ();
	}

	// NeroDone needs to be called before closing the DLL.
	// This is necessary because some clean-up actions like
	// stopping threads cannot be done in the close function of the DLL

	if (NeroDone ())
	{
		// If return value is TRUE, some memory leaks were detected.
		// 
	}

	NeroAPIGlueDone();
}

CExitCode CBurn_Cd::OpenDevice()
{
return EXITCODE_OK;
}

bool CBurn_Cd::s_bAborted = false;
CString CBurn_Cd::Wait_Cd="";

NERO_SETTINGS CBurn_Cd::s_NeroSettings =
{
	NULL,
	"ahead", "Nero - Burning Rom",
	"Nero.txt",
	{IdleCallBack, &s_NeroSettings},
	{UserDialog, &s_NeroSettings}
};

CExitCode CBurn_Cd::NeroAPIInit()
{
	//This is For Getting Nero API Version
	 WORD majhi, majlo, minhi, minlo;

  NeroGetAPIVersionEx(&majhi, &majlo, &minhi, &minlo, NULL);


  // format and display the version information

  CString strVersion;
  strVersion.Format("NeroAPI version %d.%d.%d.%d",
                    majhi, majlo, minhi, minlo);

  Report_write(strVersion);
	// Provide the this-pointer for the UserDialog callback

	s_NeroSettings.nstUserDialog.ncCallbackFunction = UserDialog;
	s_NeroSettings.nstUserDialog.ncUserData = this;

	// Do the actual initialization and map the return value
	// into our EXITCODE.

	//Use Nero Progress When Actual Burning
	npProgress.npAbortedCallback = NULL;
	npProgress.npAddLogLineCallback = AddLogLine;
	npProgress.npDisableAbortCallback = NULL;
	npProgress.npProgressCallback = ProgressCallback;
	npProgress.npSetPhaseCallback = SetPhaseCallBack;
	npProgress.npUserData = this;
	npProgress.npSetMajorPhaseCallback=SetMajorPhaseCallback;	
	npProgress.npSubTaskProgressCallback=NULL;
	Report_write("		The File is Started Running Now");
	Report_write("		*******************************");


	switch (NeroInit (&s_NeroSettings, NULL))
	{
		case NEROAPI_INIT_OK:
			Report_write("Nero SuccessFully Initialised");
			return EXITCODE_OK;
		
		case NEROAPI_INIT_INVALID_SERIAL_NUM:
			Report_write("Initialisation breaked with bad serial number");
			return EXITCODE_BAD_SERIAL_NUMBER;

		case NEROAPI_INIT_DEMOVERSION_EXPIRED:
			Report_write("The Demo Version Expired");
			return EXITCODE_DEMOVERSION_EXPIRED;
		
		case NEROAPI_INIT_ALREADY_INITIALISED:
		case NEROAPI_INIT_CANNOT_LOCK:
		case NEROAPI_INIT_UNSPECIFIED_ERROR:
		case NEROAPI_INIT_INVALID_ARGS:
		default:
			Report_write("Some Internal Error");
			return EXITCODE_INTERNAL_ERROR;
	}
}


NeroUserDlgInOut NERO_CALLBACK_ATTR CBurn_Cd::UserDialog(void *pUserData, NeroUserDlgInOut type, void *data)
{
 // handling of messages that require the user to perform an action
  // for reasons of brevity we only deal with the messages that 
  // are absolutely mandatory for this application
  switch (type)
  {
    case DLG_AUTO_INSERT:
      return DLG_RETURN_CONTINUE;
      break;
    case DLG_DISCONNECT_RESTART:
      return DLG_RETURN_ON_RESTART;
      break;
    case DLG_DISCONNECT:
      return DLG_RETURN_CONTINUE;
      break;
    case DLG_AUTO_INSERT_RESTART:
      return DLG_RETURN_EXIT;
      break;
    case DLG_RESTART:
      return DLG_RETURN_EXIT;
      break;
    case DLG_SETTINGS_RESTART:
      return DLG_RETURN_CONTINUE;
      break;
    case DLG_OVERBURN:
      return DLG_RETURN_TRUE;
      break;
    case DLG_AUDIO_PROBLEMS:
      return DLG_RETURN_EXIT;
      break;
    case DLG_FILESEL_IMAGE:
	  return DLG_RETURN_EXIT;
      break;
    case DLG_WAITCD:
	case DLG_WAITCD_DONE:
		{
		  NERO_WAITCD_TYPE waitcdType = (NERO_WAITCD_TYPE) (int)data;
		  char *waitcdString = NeroGetLocalizedWaitCDTexts (waitcdType);
		  Wait_Cd=waitcdString;
			//((CNeroFiddlesDlg*)pUserData)->AppendString(waitcdString);
			((CBurn_Cd*)pUserData)->Report_write("User Dialog");
			((CBurn_Cd*)pUserData)->Report_write(waitcdString);
		 // AfxMessageBox(waitcdString);
		  NeroFreeMem(waitcdString);
		  return DLG_RETURN_CONTINUE;
		  break;
		}
    default:
		int response=type;
		CString test;
		test.Format("The value from user dialog %d",response);
		((CBurn_Cd*)pUserData)->Report_write(test);
		AfxMessageBox("Not Coming");
      break;
 
}
  return DLG_RETURN_EXIT;
}



bool NERO_CALLBACK_ATTR CBurn_Cd::IdleCallBack(void *pUserData)
{
return s_bAborted;
}

NERO_SCSI_DEVICE_INFO CBurn_Cd::GetDeviceInfos(CString Drive_Letter)
{
		
	int count=0;
  	while(count<m_NeroDeviceInFos->nsdisNumDevInfos-1)
	{
		if (Drive_Letter == m_NeroDeviceInFos->nsdisDevInfos[count].nsdiDriveLetter)
		{
			break;
		}
		count++;
	}
	return m_NeroDeviceInFos->nsdisDevInfos[count];
	
}

NERO_DEVICEHANDLE  CBurn_Cd::GetDeviceHandle()
{
Report_write("Device Handle Successfully Returned");
return(m_NeroDeviceHandle);
}



void CBurn_Cd::SetNeroDeviceHandle(NERO_SCSI_DEVICE_INFO *nsdiDevice)
{
Report_write("The Device Set was ");
Report_write(nsdiDevice->nsdiDeviceName);
m_NeroDeviceHandle=NeroOpenDevice(nsdiDevice);
}

void CBurn_Cd::SetMedia(NERO_MEDIA_TYPE media)
{
pcMedia=media;
}

NERO_MEDIA_TYPE CBurn_Cd::GetMedia()
{
	Report_write("The Media Set was :");
	Report_write(pcMedia);
	return pcMedia;
}

bool CBurn_Cd::Calculate_Size(CNeroIsoTrack *track)
{
	
//Get Free Size From Cd
unsigned int Size_In_Cd=m_NeroCDInfo->ncdiFreeCapacityInBlocks;

//To Calculate exact size to copy use the function and
//Initialize the parameters for it

NERO_FILESYSTEMTRACK_OPTIONS pOptions;
			memset(&pOptions,0,sizeof(pOptions));
			pOptions.netsStructureSize=sizeof(pOptions);
			pOptions.netspCDStamp=m_pCDStamp;
			pOptions.netsFlags=		NBF_WRITE|NBF_CLOSE_SESSION;//|NBF_VERIFY;
			pOptions.netsDeviceHandle=m_NeroDeviceHandle;
			pOptions.netsMediaType=m_NeroCDInfo->ncdiMediaType;
			pOptions.netsFSContainer=NULL;
			pOptions.netsFSContainerFlags=NULL;
			pOptions.netsReserved[0]=0;
			unsigned int Size_To_Copy=NeroEstimateTrackSize(track,
															NETS_EXACT_SIZE,&pOptions);
					
				
					CString Report_Mess;
					Report_write("There is no Enough Space");
					Report_Mess.Format("The Space On Cd %d",Size_In_Cd);
				    Report_write(Report_Mess);
					Report_Mess.Empty();
					Report_Mess.Format("The Size To Copy %d",Size_To_Copy);
				    Report_write(Report_Mess);
				if(Size_In_Cd<Size_To_Copy) 
				{   					
					return false;
				}
				else return true;
}

CExitCode CBurn_Cd::NeroLoad()
{
	// Initialize NeroAPI.

	if (! NeroAPIGlueConnect (NULL))
	{   Report_write("Nero API DLL not found");
		return EXITCODE_NEROAPI_DLL_NOT_FOUND;
	}

	// Set the flag.

	m_bNeroInitialized = true;
    Report_write("Nero Successfully Initialised-Glue Connect Loaded");    
	return EXITCODE_OK;
}

CExitCode CBurn_Cd::WriteFiles(LPCSTR psFileName, CString Drive_Letter, int Speed, NERO_MEDIA_TYPE m_NeroType)
{
EXITCODE code;
NERO_WRITE_CD * Nero_WriteCd;
//NeroProgress npProgress;
// Calculate the size required for NERO_WRITE_CD plus the given number of tracks

	int iSize = sizeof (NERO_WRITE_CD) +  sizeof (NERO_AUDIO_TRACK);

	// Allocate the required memory and assign it to the NERO_WRITE_CD pointer

	Nero_WriteCd = (NERO_WRITE_CD *) new char[iSize];

	// Make sure the system could allocate enough memory

	if (NULL == Nero_WriteCd)
	Report_write("Memory Not Set");
	// Fill the allocated memory with null bytes
else
{
	memset (Nero_WriteCd, 0, iSize);

	// Fill in the basic information

	// no CD stamp, artist or title required
	//If It is First Time Copy csStamp is Null
    Nero_WriteCd->nwcdpCDStamp=NULL;
    Nero_WriteCd->nwcdArtist=NULL;
    Nero_WriteCd->nwcdTitle=NULL;

    // no CD Extra information available
	Nero_WriteCd->nwcdCDExtra=FALSE;

    // we have no Audio tracks
	Nero_WriteCd->nwcdNumTracks=0;

	// we want to write to a CD
	//writeCD.nwcdMediaType = MEDIA_CD;

	Nero_WriteCd->nwcdMediaType = m_NeroType;
    

	
    NERO_ISO_ITEM *pItem =NULL;
	 NERO_SCSI_DEVICE_INFO nsdiDevice=GetDeviceInfos(Drive_Letter);
//	_ASSERT(m_NeroDeviceHandle==NULL);
    SetNeroDeviceHandle(&nsdiDevice);
		
	code=GetIsoTrack(psFileName,&nsdiDevice,&Nero_WriteCd->nwcdIsoTrack,&pItem);
		
		if(code!=EXITCODE_OK){
			Report_write("Unable To Create A Track");
		//	AfxMessageBox("Error In Getting IsoTrack");
			return code;}
	else
		{//Final Check  whether there is enough space to Burn
	//	if(Calculate_Size(Nero_WriteCd->nwcdIsoTrack))
	//	{
			//This is the Actual Burning Function
			//The m_NeroDeviceHandle is the device handle for the  cdrw drive
			//Second Parameter Write in CD or DVD according to media Type
			//NBF_WRITE finally writes and close_session is to close the session
			//Allow writing Again
			int iRes = NeroBurn(m_NeroDeviceHandle, 
							NERO_ISO_AUDIO_MEDIA,
							Nero_WriteCd,
							NBF_WRITE|NBF_CLOSE_SESSION,//|NBF_VERIFY,
							Speed,
							&npProgress);
	   AfxMessageBox("After Burn");
      NeroFreeIsoTrack(Nero_WriteCd->nwcdIsoTrack);

      char* Log = NeroGetErrorLog();

      // display the error log contents

      Report_write(Log);

	  // free the log
	  NeroFreeMem(Log);


      switch(iRes)
      {
        case NEROAPI_BURN_OK:
		  code=EXITCODE_OK;
          Report_write ("BurnCD() : burn successful");
          break;
        case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
		  code=EXITCODE_UNKNOWN_CD_FORMAT;
          Report_write ("BurnCD() : unknown CD format");
          break;
        case NEROAPI_BURN_INVALID_DRIVE:
			code=EXITCODE_INVALID_DRIVE;
          Report_write ("BurnCD() : invalid drive");
          break;
        case NEROAPI_BURN_FAILED:
		  code=EXITCODE_BURN_FAILED;
          Report_write ("BurnCD() : burn failed");
          break;
        case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
		  code=EXITCODE_FUNCTION_NOT_ALLOWED;
          Report_write ("BurnCD() : function not allowed");
          break;
        case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
		  code=EXITCODE_DRIVE_NOT_ALLOWED;
          Report_write ("BurnCD() : drive not allowed");
          break;
		case NEROAPI_BURN_USER_ABORT:
		  code=EXITCODE_USER_ABORTED;
          Report_write ("BurnCD() : user aborted");
          break;
		case NEROAPI_BURN_BAD_MESSAGE_FILE:
          code=EXITCODE_BAD_MESSAGE_FILE;
          Report_write ("BurnCD() : bad message file");
          break;
        default:
          code=EXITCODE_INTERNAL_ERROR;
          Report_write ("BurnCD() : unknown error");
		  break;
      }

//	}
//		else return EXITCODE_OUT_OF_MEMORY;

	}
}

return code;
}

int CBurn_Cd::AddDeviceName(CString Device_Name[])
{
	//I am Trying To add Device Name in a Array
	CString DeviceName[5];

    for(DWORD deviceCounter=0;deviceCounter<m_NeroDeviceInFos->nsdisNumDevInfos;deviceCounter++)
	{
		DeviceName[deviceCounter]=m_NeroDeviceInFos->nsdisDevInfos[deviceCounter].nsdiDeviceName;
		//AfxMessageBox(DeviceName[deviceCounter]);
	
	Device_Name[deviceCounter]=DeviceName[deviceCounter];	
	}
    return deviceCounter;
}

void CBurn_Cd::SetDeviceInfos()
{
	_ASSERT(m_NeroDeviceInFos==NULL);
	Report_write("Setting all Device Infos");
	m_NeroDeviceInFos=NeroGetAvailableDrivesEx(MEDIA_CDRW,NULL);
}


//The Available Write Speeds are written in a integer array for user reference
int CBurn_Cd::SetAvailableSpeeds(NERO_SCSI_DEVICE_INFO* nsdiDevice,NERO_MEDIA_TYPE Media_Type,int Speed_List[])
{
	_ASSERT(m_NeroDeviceHandle==NULL);
    SetNeroDeviceHandle(nsdiDevice);
	if(m_NeroDeviceHandle)
	{
	  NERO_SPEED_INFOS* TSpeed=NeroGetAvailableSpeeds(m_NeroDeviceHandle,ACCESSTYPE_WRITE,Media_Type,NULL);
    int noExist_Speeds=TSpeed->nsiNumSupportedSpeeds;
	
	for(int dspeed=0;dspeed<noExist_Speeds;dspeed++)
	{
		if(TSpeed->nsiBaseSpeedKBs!=0)
		
		Speed_List[dspeed]=TSpeed->nsiSupportedSpeedsKBs[dspeed]/TSpeed->nsiBaseSpeedKBs;
		//else  speed[dspeed]=TSpeed->nsiSupportedSpeeds;
		
	}
	return noExist_Speeds;	
	}
return 0;
}

int CBurn_Cd::Report_write(CString Report_Data)
{try
	{
		FILE*	fpw;
		CTime tm=CTime::GetCurrentTime();
		CString strdate=tm.Format("%d-%m-%Y");
		CString strtime=tm.Format("%I:%M:%S %p");
		
		
		fpw = fopen("Burn_Cd.log","a");
		if (fpw==0)
		{
			
			return( -1 );
		}
		else
		{
			fprintf(fpw,"
");
			fprintf(fpw,strdate);
			fprintf(fpw,"	");
			
			fprintf(fpw,strtime);
			fprintf(fpw,"	");			

			
			fprintf(fpw,Report_Data);
	
			
			 fclose(fpw);
		   
			return 0;
		}
	}
	catch(...)
		{
			return -1;
		}

}

int CBurn_Cd::ValidDrive(CString Drive_Letter)
{
	int i;
	LPSTR psTrimmedDriveName = (LPSTR) _alloca(strlen(Drive_Letter)+1);
	strcpy (psTrimmedDriveName,Drive_Letter);
	//TrimRight (psTrimmedDriveName);
	for (i = 0; i < (int)(m_NeroDeviceInFos->nsdisNumDevInfos); i++) 
	{
		NERO_SCSI_DEVICE_INFO nsdiShort = m_NeroDeviceInFos->nsdisDevInfos[i];
		
		// Check if the full device name has been supplied.
        // stricmp performs a lowercase comparison and returns 0 if the strings are identical.
		
		LPSTR psTrimmedDeviceName = (LPSTR) _alloca (strlen (nsdiShort.nsdiDeviceName) + 1);
		strcpy (psTrimmedDeviceName, nsdiShort.nsdiDeviceName);
	//	TrimStringRight(psTrimmedDeviceName);

		bool bFoundDeviceName = false;
		if (0 == stricmp (psTrimmedDriveName, psTrimmedDeviceName))
		{
			bFoundDeviceName = true;
		}
		
		// Check if the user supplied drive name is only one character long
		// and see if it matches the drive letter
		bool bFoundDriveName = false;
		if(0!=nsdiShort.nsdiDriveLetter)
		{
			
				if (Drive_Letter==nsdiShort.nsdiDriveLetter)
			{
				bFoundDriveName = true;
			}
		
		}				
		// If either a device name or drive name was found try to open the device
		
		if (bFoundDeviceName || bFoundDriveName)
		{
			// We successfully found the wanted drive. Return the index.
           	return i;
		}
		
	}
    return -1;
}

int CBurn_Cd::SetSpeeds(CString Drive_Letter, NERO_MEDIA_TYPE Media_Type, int Speed_List[])
{
 int valid=ValidDrive(Drive_Letter);
 if(valid<0) 
 {	 return -1;
 }
 else{
	  //NERO_SCSI_DEVICE_INFO *nsdiDevice;
	// char Drive=(char)Drive_Letter;
	 NERO_SCSI_DEVICE_INFO nsdiDevice=GetDeviceInfos(Drive_Letter);
	_ASSERT(m_NeroDeviceHandle==NULL);
    SetNeroDeviceHandle(&nsdiDevice);
	if(m_NeroDeviceHandle)
	{
	  NERO_SPEED_INFOS* TSpeed=NeroGetAvailableSpeeds(m_NeroDeviceHandle,ACCESSTYPE_WRITE,Media_Type,NULL);
    int noExist_Speeds=TSpeed->nsiNumSupportedSpeeds;
	
	for(int dspeed=0;dspeed<noExist_Speeds;dspeed++)
	{
		if(TSpeed->nsiBaseSpeedKBs!=0)
		
		Speed_List[dspeed]=TSpeed->nsiSupportedSpeedsKBs[dspeed]/TSpeed->nsiBaseSpeedKBs;
		//else  speed[dspeed]=TSpeed->nsiSupportedSpeeds;
		
	}
	return noExist_Speeds;	
	}
	}
return 0;
}

void NERO_CALLBACK_ATTR CBurn_Cd::SetPhaseCallBack(void *pUserData, const char *text)
{
// display the current phase the burn process is currently going through
  CString csTemp(text);
  ((CBurn_Cd*)pUserData)->Report_write("Phase: " + csTemp);
  return;
}

void NERO_CALLBACK_ATTR CBurn_Cd::AddLogLine(void *pUserData, NERO_TEXT_TYPE type, const char *text)
{
// Add the text that was passed to this function to the message log
  CString csTemp(text);
  ((CBurn_Cd*)pUserData)->Report_write("Log line:" + csTemp);
  return;
}

BOOL NERO_CALLBACK_ATTR CBurn_Cd::ProgressCallback(void *pUserData, DWORD dwProgressInPercent)
{
	// print the numerical value
   
	Wait_Cd.Format("Progress Percentage : %03d%% ", dwProgressInPercent);
    ((CBurn_Cd*)pUserData)->Report_write(Wait_Cd);
	Wait_Cd="";
	// print the progress meter

	int w = (74*dwProgressInPercent)/100;
	for (int i = w; i > 0; i --)
	{
		Wait_Cd+="#";
	}

	for (i = 74 - w; i > 0; i --)
	{
		Wait_Cd+=".";
	}
    ((CBurn_Cd*)pUserData)->Report_write(Wait_Cd);
	Wait_Cd="";
	
	// We simply return the aborted flag

	return s_bAborted;
}

The Above Cpp is included and it is executed like this

#include “Burn_Cd.h”

// TODO: Add your control notification handler code here
EXITCODE code;
CBurn_Cd Burn_Cd,Burn_Cd1;
Burn_Cd.SetDeviceInfos();
Burn_Cd.SetMedia(MEDIA_DVD_ANY);
code=Burn_Cd.WriteFiles(“D:\Manjula”,“e”,0,MEDIA_DVD_ANY);
if(code!=EXITCODE_OK) AfxMessageBox(“See Burn_Cd.Log For Errors”);
else AfxMessageBox(“Burn Compiled Successfully”);



My History

9.11.2005
NeroAPI
3:31:54 PM	#1 Text 0 File Reader.cpp, Line 126
	Reader running
	
3:31:54 PM	#2 Text 0 File AudioCompilationImpl.cpp, Line 817
	DRM: StartDrmRecording(RealRec:1, ImageRec:0, Copies:1)
	DRM: Beginning burn process.
	
3:31:54 PM	#3 ISO9660GEN -11 File geniso.cpp, Line 3899
	First writeable address = 0 (0x00000000)
	
3:33:40 PM	#4 Text 0 File Burncd.cpp, Line 3152
	Turn on Disc-At-Once, using DVD media
	
3:33:41 PM	#5 Text 0 File DlgWaitCD.cpp, Line 259
	Write in overburning mode: NO
	
3:33:41 PM	#6 Text 0 File DlgWaitCD.cpp, Line 2162
	Recorder: SONY DVD RW DRU-700A, Media type: DVD+RW
	 Disc Manufacturer ID: SONY, Media Type ID: S11, Product revision number: 0
	 Disc Application Code: 0, Extended Information Indicators: 1
	
3:33:41 PM	#7 Text 0 File DlgWaitCD.cpp, Line 420
	&gt;&gt;&gt; Protocol of DlgWaitCD activities: &lt;&lt;&lt;
	=========================================
	
3:33:41 PM	#8 Text 0 File AudioCompilationImpl.cpp, Line 828
	DRM: DRM burn session terminated.
	
3:33:41 PM	#9 Text 0 File AudioCompilationImpl.cpp, Line 857
	DRM: Closing entire DRM handling. Bye.
	

Existing drivers:

Registry Keys:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\AllocateCDROMs : 0 (Security Option) 


[09.11.2005]------------------------------------
15:31:52	Robot error messages from:
====== *** NeroAPI, History File *** ======

Can NCITEF_USE_ALL_SPACE can be used in all DVD Types. My File is importing correctly and it is not writing in a dvd. It is coming first writable address null for a DVD. The same code is writing properly for cd.
:sad: If any one help me advance :clap:

Now it is Writing after i set the cd stamp m_nerocdinfo.
Thank u all.