none
Trying To Get DDiscFormat2DataEvents in c# RRS feed

  • Question


  • hi

    I have been using the interop.cs to get write updates successfully. I am now trying to get updates for AddTree. i have added code to interop.cs in the same way that code was added for the write updates but i receive no notification. Here is the code I have added to interop.cs


    [CoClass(typeof(MsftFileSystemImageClass)), ComImport]
        [Guid("2C941FE1-975B-59BE-A960-9A2A262853A5")]
        public interface MsftFileSystemImage : IFileSystemImage, FileSystemImage_Events
        {
        }

    [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void FileSystemImage_EventsHandler([In, MarshalAs(UnmanagedType.IDispatch)] object sender, [In, MarshalAs(UnmanagedType.IDispatch)] object arg1, [In, MarshalAs(UnmanagedType.IDispatch)] object arg2, [In, MarshalAs(UnmanagedType.IDispatch)] object arg3);

        [ComVisible(false), ComEventInterface(typeof(DFileSystemImageEvents), typeof(FileSystemImage_EventsProvider))]
        public interface FileSystemImage_Events
        {
            event FileSystemImage_EventsHandler Update;
        }

        [TypeLibType(TypeLibTypeFlags.FHidden), ClassInterface(ClassInterfaceType.None)]
        public sealed class FileSystemImage_SinkHelper : DFileSystemImageEvents
        {
            public FileSystemImage_SinkHelper(FileSystemImage_EventsHandler eventHandler)
            {
                if (eventHandler == null)
                    throw new ArgumentNullException("Delegate (callback function) cannot be null");
                m_dwCookie = 0;
                m_UpdateDelegate = eventHandler;
            }

            public void Update([In, MarshalAs(UnmanagedType.IDispatch)] object sender, [In, MarshalAs(UnmanagedType.IDispatch)] object arg1, [In, MarshalAs(UnmanagedType.IDispatch)] object arg2, [In, MarshalAs(UnmanagedType.IDispatch)] object arg3)
            {
                m_UpdateDelegate(sender, arg1, arg2,arg3);
            }

            public int Cookie
            {
                get
                {
                    return m_dwCookie;
                }
                set
                {
                    m_dwCookie = value;
                }
            }

            public FileSystemImage_EventsHandler UpdateDelegate
            {
                get
                {
                    return m_UpdateDelegate;
                }
                set
                {
                    m_UpdateDelegate = value;
                }
            }

            private int m_dwCookie;
            private FileSystemImage_EventsHandler m_UpdateDelegate;
        }

        [ClassInterface(ClassInterfaceType.None)]
        internal sealed class FileSystemImage_EventsProvider : FileSystemImage_Events, IDisposable
        {
            public FileSystemImage_EventsProvider(object pointContainer)
            {
                lock (this)
                {
                    if (m_ConnectionPoint == null)
                    {
                        m_aEventSinkHelpers = new Hashtable();
                        Guid eventsGuid = typeof(DFileSystemImageEvents).GUID;
                        IConnectionPointContainer connectionPointContainer = pointContainer as IConnectionPointContainer;

                        connectionPointContainer.FindConnectionPoint(ref eventsGuid, out m_ConnectionPoint);
                    }
                }
            }

            public event FileSystemImage_EventsHandler Update
            {
                add
                {
                    lock (this)
                    {
                        FileSystemImage_SinkHelper helper = new FileSystemImage_SinkHelper(value);
                        int cookie = -1;

                        m_ConnectionPoint.Advise(helper, out cookie);
                        helper.Cookie = cookie;
                        m_aEventSinkHelpers.Add(helper.UpdateDelegate, helper);
                    }
                }

                remove
                {
                    lock (this)
                    {
                        FileSystemImage_SinkHelper helper = m_aEventSinkHelpers[value] as FileSystemImage_SinkHelper;
                        if (helper != null)
                        {
                            m_ConnectionPoint.Unadvise(helper.Cookie);
                            m_aEventSinkHelpers.Remove(helper.UpdateDelegate);
                        }
                    }
                }
            }

            public void Dispose()
            {
                Cleanup();
                GC.SuppressFinalize(this);
            }

            ~FileSystemImage_EventsProvider()
            {
                Cleanup();
            }

            public void Cleanup()
            {
                Monitor.Enter(this);
                try
                {
                    foreach (DiscFormat2Data_SinkHelper helper in m_aEventSinkHelpers)
                    {
                        m_ConnectionPoint.Unadvise(helper.Cookie);
                    }

                    m_aEventSinkHelpers.Clear();
                    Marshal.ReleaseComObject(m_ConnectionPoint);
                }
                catch (SynchronizationLockException)
                {
                    return;
                }
                finally
                {
                    Monitor.Exit(this);
                }
            }

            private Hashtable m_aEventSinkHelpers;
            private IConnectionPoint m_ConnectionPoint = null;
        }

    I have tried changing the types in the update function to BStr and string, and I4 int, I4 int, but I still get the same result.


    Thursday, October 25, 2007 12:18 PM

Answers

  • Hi!

    Your code looks incomplete so I can not tell what exactly is wrong there, so let me provide code that works for me.

    Let me know if it will not work for you or you have more questions.

    Dmitry.

    Code Block

    #region DFileSystemImageEvents

     

    [CoClass(typeof(MsftFileSystemImageClass)), ComImport]

    [Guid("2C941FE1-975B-59BE-A960-9A2A262853A5")]

    public interface MsftFileSystemImage : IFileSystemImage, DFileSystemImage_Events

    {

    }

     

    [UnmanagedFunctionPointer(CallingConvention.StdCall)]

    public delegate void IMAPIEventHandlerDelegate<TSender, TArg1, TArg2, TArg3>(TSender sender, TArg1 arg1, TArg2 arg2, TArg3 arg3)

    where TSender : class;

     

    [

    ComEventInterface(typeof(DFileSystemImageEvents),

    typeof(DFileSystemImage_EventsProvider)),

    TypeLibType(TypeLibTypeFlags.FHidden)

    ]

    public interface DFileSystemImage_Events

    {

    event IMAPIEventHandlerDelegate<IFileSystemImage, String, long, long> Update;

    }

     

    [

    ComImport,

    Guid("2C941FDF-975B-59BE-A960-9A2A262853A5"),

    InterfaceType(ComInterfaceType.InterfaceIsDual)

    ]

    public interface DFileSystemImageEvents

    {

    [DispId(0x100)]

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]

    void Update(

    [In, MarshalAs(UnmanagedType.IDispatch)] IFileSystemImage sender,

    [In, MarshalAs(UnmanagedType.BStr)] String currentFile,

    long copiedSectors,

    long totalSectors);

    }

     

    [

    TypeLibType(TypeLibTypeFlags.FHidden),

    ClassInterface(ClassInterfaceType.None)

    ]

    public sealed class DFileSystemImage_SinkHelper : DFileSystemImageEvents

    {

    public void Update(

    [In, MarshalAs(UnmanagedType.IDispatch)] IFileSystemImage sender,

    [In, MarshalAs(UnmanagedType.BStr)] String currentFile,

    long copiedSectors,

    long totalSectors)

    {

    UpdateDelegate(sender, currentFile, copiedSectors, totalSectors);

    }

     

    public int Cookie;

    public IMAPIEventHandlerDelegate<IFileSystemImage, String, long, long> UpdateDelegate;

    }

     

    [ClassInterface(ClassInterfaceType.None)]

    internal sealed class DFileSystemImage_EventsProvider : DFileSystemImage_Events, IDisposable

    {

    public DFileSystemImage_EventsProvider(Object pointContainer)

    {

    lock (this)

    {

    if (m_ConnectionPoint == null)

    {

    Guid eventsGuid = typeof(DFileSystemImageEvents).GUID;

    IConnectionPointContainer connectionPointContainer = pointContainer as IConnectionPointContainer;

    connectionPointContainer.FindConnectionPoint(ref eventsGuid, out m_ConnectionPoint);

    }

    }

    }

     

    public event IMAPIEventHandlerDelegate<IFileSystemImage, String, long, long> Update

    {

    add

    {

    lock (this)

    {

    if (m_SinkHelper == null)

    {

    m_SinkHelper = new DFileSystemImage_SinkHelper()

    }

    // Add the passed-in value to the sink helper's delegate list

    m_SinkHelper.UpdateDelegate += value;

    // Call Advise on a new sink helper, initializing its cookie

    if (m_NeedsAdvise)

    {

    m_ConnectionPoint.Advise(m_SinkHelper, out m_SinkHelper.Cookie);

    m_NeedsAdvise = false;

    }

    }

    }

    remove

    {

    lock (this)

    {

    if (m_SinkHelper == null ||

    m_SinkHelper.UpdateDelegate == null)

    {

    // TODO: ERROR, cannot remove w/o adding

    }

    else

    {

    m_SinkHelper.UpdateDelegate -= value;

    if (m_SinkHelper.UpdateDelegate == null)

    {

    m_ConnectionPoint.Unadvise(m_SinkHelper.Cookie);

    m_NeedsAdvise = true;

    }

    }

    }

    }

    }

     

    // Implementation of IDisposable.Dispose

    public void Dispose()

    {

    Cleanup();

    // It is no longer necessary for the GC to call the finalizer

    GC.SuppressFinalize(this);

    }

     

    // Finalizer

    ~DFileSystemImage_EventsProvider()

    {

    Cleanup();

    }

     

    // Called to unhook all events

    private void Cleanup()

    {

    lock (this)

    {

    if (!m_NeedsAdvise)

    {

    m_ConnectionPoint.Unadvise(m_SinkHelper.Cookie);

    m_NeedsAdvise = true;

    }

    m_SinkHelper = null;

    m_ConnectionPoint = null;

    }

    }

    private bool m_NeedsAdvise = true;

    private IConnectionPoint m_ConnectionPoint = null;

    private DFileSystemImage_SinkHelper m_SinkHelper = null;

    }

    #endregion

     

    Friday, November 2, 2007 1:16 AM

All replies

  • Have I asked a stupid question or does no one know how to do this?
    I assume it is possible as Update events work from burning

    Help please??
    Tuesday, October 30, 2007 9:57 AM
  • Hello robcam,

     

    I'm not very familiar with managed code interop layer issues, which is what we believe you are experiencing.  Our test lead is working on this issue and will report back as soon as he has found something helpful.  However, he is a bit busy at the moment.

     

    I just wanted to let you know that the issue has not been forgotten but that we will need a little time to get back to you as it seems to be a little more in-depth issue than I had expected =)

     

    In the mean time, please let me know if you have any other questions!

     

    thanks,

     

    Garrett Jacobson

     

    Wednesday, October 31, 2007 11:13 PM
  • Hi!

    Your code looks incomplete so I can not tell what exactly is wrong there, so let me provide code that works for me.

    Let me know if it will not work for you or you have more questions.

    Dmitry.

    Code Block

    #region DFileSystemImageEvents

     

    [CoClass(typeof(MsftFileSystemImageClass)), ComImport]

    [Guid("2C941FE1-975B-59BE-A960-9A2A262853A5")]

    public interface MsftFileSystemImage : IFileSystemImage, DFileSystemImage_Events

    {

    }

     

    [UnmanagedFunctionPointer(CallingConvention.StdCall)]

    public delegate void IMAPIEventHandlerDelegate<TSender, TArg1, TArg2, TArg3>(TSender sender, TArg1 arg1, TArg2 arg2, TArg3 arg3)

    where TSender : class;

     

    [

    ComEventInterface(typeof(DFileSystemImageEvents),

    typeof(DFileSystemImage_EventsProvider)),

    TypeLibType(TypeLibTypeFlags.FHidden)

    ]

    public interface DFileSystemImage_Events

    {

    event IMAPIEventHandlerDelegate<IFileSystemImage, String, long, long> Update;

    }

     

    [

    ComImport,

    Guid("2C941FDF-975B-59BE-A960-9A2A262853A5"),

    InterfaceType(ComInterfaceType.InterfaceIsDual)

    ]

    public interface DFileSystemImageEvents

    {

    [DispId(0x100)]

    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]

    void Update(

    [In, MarshalAs(UnmanagedType.IDispatch)] IFileSystemImage sender,

    [In, MarshalAs(UnmanagedType.BStr)] String currentFile,

    long copiedSectors,

    long totalSectors);

    }

     

    [

    TypeLibType(TypeLibTypeFlags.FHidden),

    ClassInterface(ClassInterfaceType.None)

    ]

    public sealed class DFileSystemImage_SinkHelper : DFileSystemImageEvents

    {

    public void Update(

    [In, MarshalAs(UnmanagedType.IDispatch)] IFileSystemImage sender,

    [In, MarshalAs(UnmanagedType.BStr)] String currentFile,

    long copiedSectors,

    long totalSectors)

    {

    UpdateDelegate(sender, currentFile, copiedSectors, totalSectors);

    }

     

    public int Cookie;

    public IMAPIEventHandlerDelegate<IFileSystemImage, String, long, long> UpdateDelegate;

    }

     

    [ClassInterface(ClassInterfaceType.None)]

    internal sealed class DFileSystemImage_EventsProvider : DFileSystemImage_Events, IDisposable

    {

    public DFileSystemImage_EventsProvider(Object pointContainer)

    {

    lock (this)

    {

    if (m_ConnectionPoint == null)

    {

    Guid eventsGuid = typeof(DFileSystemImageEvents).GUID;

    IConnectionPointContainer connectionPointContainer = pointContainer as IConnectionPointContainer;

    connectionPointContainer.FindConnectionPoint(ref eventsGuid, out m_ConnectionPoint);

    }

    }

    }

     

    public event IMAPIEventHandlerDelegate<IFileSystemImage, String, long, long> Update

    {

    add

    {

    lock (this)

    {

    if (m_SinkHelper == null)

    {

    m_SinkHelper = new DFileSystemImage_SinkHelper()

    }

    // Add the passed-in value to the sink helper's delegate list

    m_SinkHelper.UpdateDelegate += value;

    // Call Advise on a new sink helper, initializing its cookie

    if (m_NeedsAdvise)

    {

    m_ConnectionPoint.Advise(m_SinkHelper, out m_SinkHelper.Cookie);

    m_NeedsAdvise = false;

    }

    }

    }

    remove

    {

    lock (this)

    {

    if (m_SinkHelper == null ||

    m_SinkHelper.UpdateDelegate == null)

    {

    // TODO: ERROR, cannot remove w/o adding

    }

    else

    {

    m_SinkHelper.UpdateDelegate -= value;

    if (m_SinkHelper.UpdateDelegate == null)

    {

    m_ConnectionPoint.Unadvise(m_SinkHelper.Cookie);

    m_NeedsAdvise = true;

    }

    }

    }

    }

    }

     

    // Implementation of IDisposable.Dispose

    public void Dispose()

    {

    Cleanup();

    // It is no longer necessary for the GC to call the finalizer

    GC.SuppressFinalize(this);

    }

     

    // Finalizer

    ~DFileSystemImage_EventsProvider()

    {

    Cleanup();

    }

     

    // Called to unhook all events

    private void Cleanup()

    {

    lock (this)

    {

    if (!m_NeedsAdvise)

    {

    m_ConnectionPoint.Unadvise(m_SinkHelper.Cookie);

    m_NeedsAdvise = true;

    }

    m_SinkHelper = null;

    m_ConnectionPoint = null;

    }

    }

    private bool m_NeedsAdvise = true;

    private IConnectionPoint m_ConnectionPoint = null;

    private DFileSystemImage_SinkHelper m_SinkHelper = null;

    }

    #endregion

     

    Friday, November 2, 2007 1:16 AM