locked
IMAPI Updates event does not fire in C# WPF Application RRS feed

  • Question

  • I am having a problem with a C# WPF Application that uses the IMAPI Interop writtern by Eric Hadden (http://www.codeproject.com/KB/miscctrl/imapi2.aspx )

    I succesfully wrote a cd burning application using Forms that featured a progress bar and status message that updated dynamically as cds burnt by subscribing to the MsftDiscFormat2TrackAtOnceBurner.Update event. However, when I ported this application to WPF, using very similar code, the Update event stopped firing. The cd still burns as before, just no progress report:

    Typical Code:

    class Burner
    {
    
    BackgroundBurner burnerThread;
    MsftDiscMaster2 discMaster;
    IDiscRecorder2 device;
    MsftDiscFormat2TrackAtOnce audioCd;
    
    public Burner()
    {
    burnerThread = new BackgroundWorker();
    burnerThread.DoWork += new DoWorkEventHandler(BurnerThread);
    burnerThread.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
    
    discMaster = new MsftDiscMaster2();
    device = new MsftDiscRecorder2();
    device.InitializeDiscRecorder(discMaster[0]);
    
    burnerThread.RunWorkerAsync();
    }
    
    public void BurnerThread(object sender, DoWorkEventArgs e)
    {
    
    audioCd.Update += new DiscFormat2TrackAtOnce_EventHandler(Update);
    audioCd.PrepareMedia();
    System.Runtime.InteropServices.ComTypes.IStream stream = null;
    SHCreateStreamOnFile([somefile], 0x00000000 | 0x00000040, ref stream);
    audioCd.AddAudioTrack(stream);
    audioCd.ReleaseMedia();
    audioCd.Update -= Update;
    
    }
    
    public void Update(object sender, object progress)
    {
    
    // This event does not fire! This is what I'm having the problem with.
    // Code to process progress message and percent burnerThread.ReportProgress(progresspercent, message);
    } }
    I'm really struggling to find a solution for this problem. Any help would really be appreciated. Thanks for helping out a first-time poster. I can provide more information if needed.

    Leon
    Sunday, October 4, 2009 9:32 PM

Answers

  • In order to get the update notifications in a C# application, you must set the ComVisible attribute to true.  I think it would be the same for a WPF application.

    • Marked as answer by lbarnard86 Monday, October 5, 2009 6:55 PM
    Monday, October 5, 2009 5:09 AM

All replies

  • In order to get the update notifications in a C# application, you must set the ComVisible attribute to true.  I think it would be the same for a WPF application.

    • Marked as answer by lbarnard86 Monday, October 5, 2009 6:55 PM
    Monday, October 5, 2009 5:09 AM
  • Thanks for the answer, and thanks for taking the time to write those excellent articles and the IMAPI Interop.

    I'm an amateur programmer and I write charitable software. You have no idea how helpful you've been.
    Monday, October 5, 2009 6:58 PM
  • No problem.  Glad I could help.
    Monday, October 5, 2009 8:44 PM
  • Hi,

     

    I found on MSDN that class should be marked as follows:

     

     [ComVisible(true)]

     

    class Burner
    {
    
    BackgroundBurner burnerThread;
    MsftDiscMaster2 discMaster;
    IDiscRecorder2 device;
    MsftDiscFormat2TrackAtOnce audioCd;
    }

    However, I still don't get update notifications. What am I doing wrong? Please help.

     

     

    Tuesday, November 30, 2010 3:25 PM
  • I found that the way to solve this issue is actually modifying AssemblyInfo.cs file and setting the attribute comvisible to true. This is also done in Eric's solution. My previous comment does not work.

     

    Best,

    Mert.

    Tuesday, November 30, 2010 3:34 PM