DLL crashes - Code ok?

vbimport

#1

Ok, I will try one more thing before switching to IMAPI2. I have created a C++ Class CAtapiBrenner (using Visual Studio 6.0) which wraps the Nero-API. When trying to burn some files the DLL crashes. Since nobody has an Idea what could cause this I will post some of the source-code, hoping that somebody will be able to point out the error. Here goes:

The Class is used as follows:


CAtapiBrenner Brenner;

Brenner.SetLogPath("D:\\Daten\\CAtapiBrenner.log");

if(Brenner.Init())
{

        Brenner.AddFile("D:\\DATEN\\Avus\\avus_01-23-00.prt");

        Brenner.SetVolumeName("Datensicherung Mittwoch");

        if(!Brenner.BurnSelection())
          // some error handling

        Brenner.Close();
}

The Init-method:

bool CAtapiBrenner::Init()
{
    // Liste der zu brennenden Dateien löschen
    FileList.RemoveAll();
    m_TotalFileSize = 0;

    // Progressbar initialisieren
    m_npProgress.npAbortedCallback			= AbortedCallback;
    m_npProgress.npAddLogLineCallback		= AddLogLine;
    m_npProgress.npDisableAbortCallback		= NULL;
    m_npProgress.npProgressCallback			= ProgressCallback;
    m_npProgress.npSetPhaseCallback			= SetPhaseCallback;
    m_npProgress.npUserData					= this;
    m_npProgress.npSetMajorPhaseCallback	= NULL;	
    m_npProgress.npSubTaskProgressCallback	= NULL;

    memset(m_NeroFilesPath, 0x00, sizeof(m_NeroFilesPath));
    memset(m_Vendor, 0x00, sizeof(m_Vendor));
    memset(m_Software, 0x00, sizeof(m_Software));
    memset(m_LanguageFile, 0x00, sizeof(m_LanguageFile));

    strcpy(m_NeroFilesPath, "NeroFiles");
    strcpy(m_Vendor, "Nero");
    strcpy(m_Software, "CAtapiBrenner");
    strcpy(m_LanguageFile, "Nero.txt");

    // NeroAPI initialisieren
    m_nsSettings.nstNeroFilesPath                   = m_NeroFilesPath;
    m_nsSettings.nstVendor		                    = m_Vendor;
    m_nsSettings.nstSoftware					    = m_Software;
    m_nsSettings.nstLanguageFile					= m_LanguageFile;
    m_nsSettings.nstUserDialog.ncCallbackFunction   = UserDialog;
    m_nsSettings.nstUserDialog.ncUserData			= this;
    m_nsSettings.nstIdle.ncCallbackFunction         = NULL; //IdleCallback;      
    //m_nsSettings.nstIdle.ncUserData				    = this;

    // Verbindung zur Nero-Api herstellen
    if (!NeroAPIGlueConnect(NULL)) 
	{
		DisplayError("Keine Verbindung zur NeroApi-DLL möglich!");
		return false;
	}
	
    // Version ermitteln
	WORD ver1, ver2, ver3, ver4;
	if (!NeroGetAPIVersionEx(&ver1,&ver2,&ver3,&ver4,NULL))
	{
		DisplayError("Version nicht zu ermitteln!");
		return false;
	}

    // Nero-Api initialisieren
	NEROAPI_INIT_ERROR initErr=NeroInit (&m_nsSettings,NULL);
	switch (initErr) 
	{
	    case NEROAPI_INIT_OK:
		    break;
	    case NEROAPI_INIT_INVALID_ARGS:
		    DisplayError ("NeroInit() : invalid args");
		    return false;
		    break;
	    case NEROAPI_INIT_INVALID_SERIAL_NUM:
		    DisplayError ("NeroInit() : invalid serial number");
		    return false;
		    break;
	    case NEROAPI_INIT_DEMOVERSION_EXPIRED:
		    DisplayError ("NeroInit() : demo version has expired");
		    return false;
		    break;
	    case NEROAPI_INIT_CANNOT_LOCK:
		    DisplayError ("NeroInit() : cannot lock");
		    return false;
		    break;
	    default:
	    case NEROAPI_INIT_UNSPECIFIED_ERROR:
		    DisplayError ("NeroInit() : unspecified error");
		    return false;
            break;
	}
	//NERO_SCSI_DEVICE_INFOS	*m_NeroDeviceInfos2;

	// Vorhandene (Brenn-)Laufwerke ermitteln
    m_NeroDeviceInfos = NeroGetAvailableDrivesEx (MEDIA_DVD_ANY, NULL);
	if (!m_NeroDeviceInfos)
    {
		DisplayError ("Fehler beim Ermitteln von verfügbaren Laufwerken");
		return false;
	}

    m_InitDone = true;

    return true;
}

The BurnSelection-method:

bool CAtapiBrenner::BurnSelection(bool Multisession, bool EjectMediumWhenFinished)
{
    ASSERT(m_InitDone == true);
    ASSERT(FileList.GetSize() > 0);

	// Speicher freigeben
	ClearMemory();

	size_t stTheSize = sizeof(NERO_WRITE_CD); // + (FileList.GetSize() * sizeof(NERO_ISO_ITEM));
	m_WriteCD		 = (NERO_WRITE_CD*)malloc(stTheSize);
	memset(m_WriteCD, 0, stTheSize);

    // Erstmal verkettete Liste von ISO-Items erstellen
	m_PrevIsoItem = NULL;
	m_StartIsoItem = NULL;
    for (int index = 0; index < FileList.GetSize(); ++index)
	{
        if(FileList.GetAt(index).GetLength() > 1)
        {
			NERO_ISO_ITEM* pniiNewItem = NeroCreateIsoItem();
            char path[512];
            char* name = NULL;
            char FullFile[1024];

            memset(FullFile, 0x00, sizeof(FullFile));
			memset(pniiNewItem, 0x00, sizeof(NERO_ISO_ITEM));
			memset(path, 0x00, sizeof(path));

            if (m_StartIsoItem == NULL)	// mniiFile refer to the first item
				m_StartIsoItem = pniiNewItem;

            sprintf(FullFile, "%s", FileList.GetAt(index));
    		GetFullPathName(FullFile, sizeof(path), path, &name);
    
            pniiNewItem->longFileName		= strdup(name); 
			pniiNewItem->longSourceFilePath	= strdup(path);
			pniiNewItem->isDirectory		= FALSE;
			pniiNewItem->isReference		= FALSE;
			pniiNewItem->unicodeFileName	= NULL;
			pniiNewItem->nextItem			= NULL;

			if(m_PrevIsoItem)
				m_PrevIsoItem->nextItem = pniiNewItem;
			m_PrevIsoItem = pniiNewItem;
        }
    }

    // Falls noch kein Laufwerk zugeordnet wurde, dass erste brennfähige Laufwerk suchen
    if (m_DriveLetter == 0x00)
    {
		for (int i = 0; i < m_NeroDeviceInfos->nsdisNumDevInfos; i++) 
		{
            if(m_NeroDeviceInfos->nsdisDevInfos[i].nsdiDevType == NEA_SCSI_DEVTYPE_WORM)
            {
    			m_DriveLetter = m_NeroDeviceInfos->nsdisDevInfos[i].nsdiDriveLetter;

	    		m_NeroDeviceHandle = NeroOpenDevice (&m_NeroDeviceInfos->nsdisDevInfos[i]);
		
                m_SelectedDeviceInfo=&m_NeroDeviceInfos->nsdisDevInfos[i];
				if (!m_NeroDeviceHandle) 
				{
					DisplayError ("Fehler beim initialisieren des Laufwerks!");
					ClearMemory();
                    return false;
				}
				break;
			}
		}
		if (!m_NeroDeviceHandle)
        {
			DisplayError("Kein WORM-Laufwerk gefunden!");
			ClearMemory();
            return false;
		}
	}

    if(!HasEnoughSpace())
    {
		DisplayError("Nicht genug Speicherplatz auf dem Medium!");
		ClearMemory();
        return false;
    }

    m_WriteCD->nwcdpCDStamp		= NULL;
    m_WriteCD->nwcdArtist		= NULL;
    m_WriteCD->nwcdTitle		= NULL;
    m_WriteCD->nwcdCDExtra		= FALSE;
    m_WriteCD->nwcdNumTracks	= 0;
    m_WriteCD->nwcdMediaType	= MEDIA_CD; //NeroGetCurrentMediumType(m_NeroDeviceHandle);
    m_WriteCD->nwcdIsoTrack		= NeroCreateIsoTrackEx(m_StartIsoItem, m_VolumeName, NCITEF_CREATE_ISO_FS|NCITEF_USE_JOLIET);

    DWORD BurnFlags = NBF_WRITE;

    if(Multisession == true)
        BurnFlags |= NBF_CLOSE_SESSION;
    if(EjectMediumWhenFinished == false)
        BurnFlags |= NBF_DISABLE_EJECT;

	Log("

Beginne neuen Brennvorgang!
");

    // Alle Dateien brennen
    int iRes = NeroBurn(m_NeroDeviceHandle, NERO_ISO_AUDIO_CD, m_WriteCD, BurnFlags, 0, &m_npProgress);

	if(iRes != NEROAPI_BURN_OK)
	{
		m_NeroLog = NeroGetErrorLog();

		Log(m_NeroLog);
	}

    // Ergebnis vom Brennen überprüfen
    switch(iRes)
    {
        case NEROAPI_BURN_OK:
          break;
        case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
            DisplayError("BurnCD() : unknown CD format");
            return false;
            break;
        case NEROAPI_BURN_INVALID_DRIVE:
            DisplayError("BurnCD() : invalid drive");
            return false;
            break;
        case NEROAPI_BURN_FAILED:
            DisplayError("BurnCD() : burn failed");
            return false;
            break;
        case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
            DisplayError("BurnCD() : function not allowed");
            return false;
            break;
        case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
            DisplayError("BurnCD() : drive not allowed");
            return false;
            break;
        case NEROAPI_BURN_USER_ABORT:
            DisplayError("BurnCD() : user aborted");
            return false;
            break;
        case NEROAPI_BURN_BAD_MESSAGE_FILE:
            DisplayError("BurnCD() : bad message file");
            return false;
            break;
        default:
            DisplayError("BurnCD() : unknown error");
            return false;
            break;
    }
    return true;
}

The Program crashes after calling NeroBurn() :frowning: