2010-11-29 11 views
4

J'ai intégré avec succès IMAPI2 en utilisant Interop.cs dans mon application. Je peux graver des CD/DVD sans aucun problème. Toutefois, le gestionnaire d'événements pour la mise à jour MsftDiscFormat2Data ne fonctionne pas, donc je ne peux pas déplacer ma barre de progression.MsftDiscFormat2Data Gestionnaire d'événements

Voici le code que je trouve sur le site Web CodeProject:

private void backgroundBurnWorker_DoWork (expéditeur d'objet, DoWorkEventArgs e) { MsftDiscRecorder2 DiscRecorder = null; MsftDiscFormat2Data discFormatData = null;

 try 
     { 
      // 
      // Create and initialize the IDiscRecorder2 object 
      // 
      discRecorder = new MsftDiscRecorder2(); 
      var burnData = (BurnData)e.Argument; 
      discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId); 

      // 
      // Create and initialize the IDiscFormat2Data 
      // 
      discFormatData = new MsftDiscFormat2Data 
       { 
        Recorder = discRecorder, 
        ClientName = ClientName, 
        ForceMediaToBeClosed = _closeMedia 
       }; 

      // 
      // Set the verification level 
      // 
      var burnVerification = (IBurnVerification)discFormatData; 
      burnVerification.BurnVerificationLevel = _verificationLevel; 

      // 
      // Check if media is blank, (for RW media) 
      // 
      object[] multisessionInterfaces = null; 
      if (!discFormatData.MediaHeuristicallyBlank) 
      { 
       multisessionInterfaces = discFormatData.MultisessionInterfaces; 
      } 

      // 
      // Create the file system 
      // 
      IStream fileSystem; 
      if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem)) 
      { 
       e.Result = -1; 
       return; 
      } 

      // 
      // add the Update event handler 
      // 
      discFormatData.Update += discFormatData_Update; 

      // 
      // Write the data here 
      // 
      try 
      { 
       discFormatData.Write(fileSystem); 
       e.Result = 0; 
      } 
      catch (COMException ex) 
      { 
       e.Result = ex.ErrorCode; 
       MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed", 
        MessageBoxButtons.OK, MessageBoxIcon.Stop); 
      } 
      finally 
      { 
       if (fileSystem != null) 
       { 
        Marshal.FinalReleaseComObject(fileSystem); 
       } 
      } 

      // 
      // remove the Update event handler 
      // 
      discFormatData.Update -= discFormatData_Update; 

      if (_ejectMedia) 
      { 
       discRecorder.EjectMedia(); 
      } 
     } 
     catch (COMException exception) 
     { 
      // 
      // If anything happens during the format, show the message 
      // 
      MessageBox.Show(exception.Message); 
      e.Result = exception.ErrorCode; 
     } 
     finally 
     { 
      if (discRecorder != null) 
      { 
       Marshal.ReleaseComObject(discRecorder); 
      } 

      if (discFormatData != null) 
      { 
       Marshal.ReleaseComObject(discFormatData); 
      } 
     } 
    } 

discFormatData_Update void ([In, MarshalAs (UnmanagedType.IDispatch)] expéditeur d'objet, [En, MarshalAs (UnmanagedType.IDispatch)] Progrès de l'objet) { // // Vérifiez si nous avons annulé // si (backgroundBurnWorker.CancellationPending) { var format2Data = (IDiscFormat2Data) expéditeur; format2Data.CancelWrite(); retour; }

 var eventArgs = (IDiscFormat2DataEventArgs)progress; 

     _burnData.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_WRITING; 

     // IDiscFormat2DataEventArgs Interface 
     _burnData.elapsedTime = eventArgs.ElapsedTime; 
     _burnData.remainingTime = eventArgs.RemainingTime; 
     _burnData.totalTime = eventArgs.TotalTime; 

     // IWriteEngine2EventArgs Interface 
     _burnData.currentAction = eventArgs.CurrentAction; 
     _burnData.startLba = eventArgs.StartLba; 
     _burnData.sectorCount = eventArgs.SectorCount; 
     _burnData.lastReadLba = eventArgs.LastReadLba; 
     _burnData.lastWrittenLba = eventArgs.LastWrittenLba; 
     _burnData.totalSystemBuffer = eventArgs.TotalSystemBuffer; 
     _burnData.usedSystemBuffer = eventArgs.UsedSystemBuffer; 
     _burnData.freeSystemBuffer = eventArgs.FreeSystemBuffer; 

     // 
     // Report back to the UI 
     // 
     backgroundBurnWorker.ReportProgress(0, _burnData); 
    } 

Malheureusement, le gestionnaire de mise à jour ne fait jamais appelé. J'ai cherché partout sur internet mais je n'ai pas trouvé de solution. J'ai vu des gens avec le même problème mais personne n'a été capable de répondre. Le code original d'Eric, http://www.codeproject.com/KB/miscctrl/imapi2.aspx?msg=2695517, fonctionne pour une raison quelconque.

Quelqu'un peut-il m'aider s'il vous plaît?

Répondre

7

Je sais, c'est trop tard, mais j'ai le même problème avec les rappels de mise à jour.

Ouvrir le projet-> Propriétés-> Application-> Informations sur l'assemblage et cocher "Make Assembly COM-visible".

+1

Est-ce une réponse? Si oui, développez-le. Sinon, supprimez-le. –

+1

Ouah !!!! Vous venez de m'aider à résoudre un problème que j'essaie de comprendre depuis maintenant un mois !!! merci et bonne année! – Vova