烧录多区段CD-R后,会话活动错误 [英] wrong session active after burning multisession CD-R

查看:93
本文介绍了烧录多区段CD-R后,会话活动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写代码,使用IMAPI2和CVI / LabWindows 2010 IDE将文件刻录到CD / DVD。 该代码适用于空白光盘,但当我尝试进行后续刻录时,之后只能看到第一个会话中的文件。 即使我以前在Windows中进行过多次烧伤,也会发生
。 例如:

I am trying to write code to burn files to CD/DVD using IMAPI2 and the CVI/LabWindows 2010 IDE.  The code works fine for blank discs, but when I try to do subsequent burns, only the files from the first session are visible afterward.  This happens even when I've previously done multiple burns in Windows.  For example:

我在资源管理器中将c:\ dir1刻录到光盘。 光盘现在包含dir1。 然后我在资源管理器中将c:\dir2刻录到光盘,光盘显示dir1和dir2。 然后我运行代码并尝试刻录c:\dir3并且光盘返回仅显示dir1。

I burn c:\dir1 to the disc in Explorer.  The disc now contains dir1.  Then I burn c:\dir2 to the disc in Explorer and the disc shows both dir1 and dir2.  Then I run the code and try to burn c:\dir3 and the disc goes back to showing only dir1.

我写的代码如下。 它源于MSDN上的代码
http://msdn.microsoft.com/en-us/library/windows/desktop/bb870772(v=VS.85).aspx
。 类名和命令的格式是不同的,因为LabWindows使用C而不是C ++,但代码的一般流程是相同的。 我在Windows 7 Professional 64位上运行

The code I wrote is below.  It is derived from the code on MSDN at http://msdn.microsoft.com/en-us/library/windows/desktop/bb870772(v=VS.85).aspx.  The class names and the format of the commands are different because LabWindows uses C instead of C++, but the general flow of the code is the same.  I'm running on Windows 7 Professional 64-bit.

- Rich Ferrara

-- Rich Ferrara


#include <userint.h>
#include <imapi2.h>
#include <imapi2error.h>
#include <imapi2fs.h>
#include <ansi_c.h>
#include <toolbox.h>
#include <imapi2fserror.h>
#include "imapi2ActiveX.h"
#include "imapi2FsActiveX.h"
#include "archives_defs.h"

// Master control object for all drives
static CAObjHandle discMaster;
    
// Arrays of drive handles and information (names, letters, media types)
static CAObjHandle *cdDriveHandles;
static char **cdDriveNames;
static char **cdDrivePaths;
static MediaType **cdDriveMedia;
static IMAPI2FSType_IStream cdImageStream;

// Number of recordable drives present in the system
static long numDrives;

int main(void)
{
    CmtThreadFunctionID threadId;
    int status;
    
    InitializeCdDrives();
    
    BurnCd(cdDriveHandles[0], IMAPI2FSConst_IMAPI_MEDIA_TYPE_CDR);
    
    MessagePopup("cd burn", "done");
    
    CleanUpCdDriveMemory();
    
    return 0;
}

int InitializeCdDrives(void)
{
    HRESULT result;
    SAFEARRAY *safeArrayPtr;
    CAObjHandle format;
    VARIANT *varArray;
    MediaType *media;
    size_t numElements;
    long index;
    int i;
    char *str;
    int error = E_CVIAUTO_NO_ERROR;
    
    // Read the number of CD/DVD drives in the system
    errChk(IMAPI2_NewIDiscMaster2 (NULL, 1, LOCALE_NEUTRAL, 0, &discMaster));
    errChk(IMAPI2_IDiscMaster2GetCount (discMaster, NULL, &numDrives));
                               
    // Allocate memory to hold lists of CD/DVD drive information
    cdDriveNames   = malloc(numDrives * (int)sizeof(char *));
    cdDriveHandles = malloc(numDrives * (int)sizeof(CAObjHandle));
    cdDrivePaths   = malloc(numDrives * (int)sizeof(char *));
    cdDriveMedia   = malloc(numDrives * (int)sizeof(MediaType *));
    nullChk(cdDriveNames);
    nullChk(cdDriveHandles);
    nullChk(cdDrivePaths);
    nullChk(cdDriveMedia);
    
    for (index=0; index<numDrives; ++index)
    {
        // Read a CD drive device name
        errChk(IMAPI2_IDiscMaster2GetItem (discMaster, NULL, index, 
            &cdDriveNames[index]));
        
        // Set up a handle for this device
        errChk(IMAPI2_NewIDiscRecorder2 (NULL, 1, LOCALE_NEUTRAL, 0, 
            &cdDriveHandles[index]));
        errChk(IMAPI2_IDiscRecorder2InitializeDiscRecorder (
            cdDriveHandles[index], NULL, cdDriveNames[index]));
       
        // Get the device's drive letter
        errChk(IMAPI2_IDiscRecorder2GetVolumePathNames (cdDriveHandles[index],
            NULL, &safeArrayPtr)); 
        errChk(CA_SafeArrayTo1DArrayEx (&safeArrayPtr, CAVT_VARIANT, 0, &varArray, 
            &numElements));
        errChk(CA_VariantGetCString (&varArray[0], &cdDrivePaths[index]));
        CA_FreeMemory(varArray);
        
        // Get the media types supported by this device
        errChk(IMAPI2_NewIDiscFormat2Data (NULL, 1, LOCALE_NEUTRAL, 0,
            &format));
        errChk(IMAPI2_IDiscFormat2DataSetRecorder (format, NULL, 
            cdDriveHandles[index]));
        errChk(IMAPI2_IDiscFormat2DataGetSupportedMediaTypes (format, NULL, 
            &safeArrayPtr));
        errChk(CA_SafeArrayTo1DArrayEx (&safeArrayPtr, CAVT_VARIANT, 0, &varArray,
            &numElements));
        cdDriveMedia[index] = malloc(numElements * (int)sizeof(long));
        media = cdDriveMedia[index];
        for (i=0; i<numElements; ++i)
        {
            errChk(CA_VariantGetLong (&varArray[i], (long *)&media[i])); 
        }
        CA_FreeMemory(varArray);
    }
    
Error:
    return error;
}    
      
int BurnCd(CAObjHandle drive, MediaType media)
{
    IMAPI2FSObj_IFileSystemImageResult resultImage;
    IMAPI2FSObj_IFsiDirectoryItem root;
    enum IMAPI2FSEnum_FsiFileSystems fileSystem;
    CAObjHandle discFormat;
    CAObjHandle image;
    SAFEARRAY *multiSession = NULL;
    VBOOL blank;
    int error = E_CVIAUTO_NO_ERROR;
    
    // Lock the disc drive
    errChk(IMAPI2_IDiscRecorder2AcquireExclusiveAccess (drive, NULL, 
        VTRUE, "RDP-PLATE"));
    
    // Set up the CD file system
    errChk(IMAPI2_NewIDiscFormat2Data (NULL, 1, LOCALE_NEUTRAL, 0, 
        &discFormat));
    errChk(IMAPI2_IDiscFormat2DataSetRecorder (discFormat, NULL, drive));
    errChk(IMAPI2_IDiscFormat2DataSetClientName (discFormat, NULL, 
        "RDP-PLATE"));

    // Set up the disc file system
    errChk(IMAPI2FS_NewIFileSystemImage3 (NULL, 1, LOCALE_NEUTRAL, 0, 
        &image));
   
    // Is the disc blank?   
    errChk(IMAPI2_IDiscFormat2GetMediaPhysicallyBlank (discFormat, NULL,
        &blank));

    if (blank == VTRUE)
    {
        // Set up a new blank file system
        errChk(IMAPI2FS_IFileSystemImage3ChooseImageDefaults (image, 
            NULL, drive));
    }
    else
    {
        // Retrieve the folder structure already on the disc
        errChk(IMAPI2_IDiscFormat2DataGetMultisessionInterfaces (discFormat,
            NULL, &multiSession));
        errChk(IMAPI2FS_IFileSystemImage3SetMultisessionInterfaces (
            image, NULL, multiSession));
        errChk(IMAPI2FS_IFileSystemImage3ImportFileSystem (
            image, NULL, &fileSystem));
    }
    
    // Get the image root
    errChk(IMAPI2FS_IFileSystemImage3GetRoot (image, NULL, &root));

    // Add files
    errChk(IMAPI2FS_IFsiDirectoryItemAddTree (root, NULL, "c:\\rich\\fizz", 
        VTRUE));
    
    // Create the result image and stream
    errChk(IMAPI2FS_IFileSystemImage3CreateResultImage (image, NULL, 
        &resultImage));
    errChk(IMAPI2FS_IFileSystemImageResultGetImageStream (resultImage, 
        NULL, &cdImageStream));
    
    // Burn the disc
    errChk(IMAPI2_IDiscFormat2DataWrite (discFormat, NULL, cdImageStream));
    
    // Unlock the disc drive
    errChk(IMAPI2_IDiscRecorder2ReleaseExclusiveAccess (drive, NULL));
    
Error:
    printf ("cd burn status = %x\n", error);
    return error;
}

void CleanUpCdDriveMemory(void)
{
    int index;
    
    for (index=0; index<numDrives; ++index)
    {
        free(cdDriveMedia[index]);
    }
    free(cdDriveMedia);
    free(cdDrivePaths);
    free(cdDriveHandles);
    free(cdDriveNames);
}

推荐答案

费拉拉

 

我在My Dell inspiron计算机上遇到了同样的问题,安装了Window7。

I meet the same problem with you on My Dell inspiron machine, installed Window7.

您试用的一个区别就是我我正在尝试使用C#。

One difference with your trial is that I'm trying with C#.

尚未解决此问题?

 

我需要帮助..

 

谢谢。


这篇关于烧录多区段CD-R后,会话活动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆