CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    76

    problem implementing a com component callback procedure

    Hi

    I am working with a com component, which I have added a reference to in my C#. I am using windows vista (32 bit) and VS2005.

    I have to implement a callback object which handles data being returned from the com object, which derives from an interface called IDeviceEvents which is part of the com component, which I have attempted to do in my c# code:

    Code:
    unsafe class cFM2Notify : IDeviceEvents
    {
        public string m_CallbackEvent = "";
    
        public void NotifyData(IFM2DeviceEvents CallbackData)
        {
        }
    
        public string CallbackEvent
        {
            get
            {
                return m_CallbackEvent = CallbackEvent;
            }
    
            set
            {
                CallbackEvent = m_CallbackEvent;
            }
        }
    }

    This is a shortened version - there are actually a few more properties and methods that I am required to implement, other than the ones shown.

    The code builds ok, however, it falls over when run, a StackOverflowException being generated.

    My VB.net colleague has suggested that I make the class com visible by prefixing the cFM2Notify declaration with[ComVisible(true)]. However I still a StackOverflowException being generated.

    Any ideas on what I am doing wrong?

    Cheers

    Simon

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: problem implementing a com component callback procedure

    You're not writing VB here you know : we have the 'return' keyword in C# for returning values from functions.

    The problem lies in your CallbackEvent property - it should be :

    Code:
        public string CallbackEvent
        {
            get
            {
                return m_CallbackEvent;
            }
    
            set
            {
                m_CallbackEvent = value;
            }
        }
    If you've coded your other properties the same way then they will need changing too.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jan 2003
    Posts
    76

    Re: problem implementing a com component callback procedure

    Hi Darwen

    Thanks for the reply, it now works. Rather silly mistake on my part

    thanks again

    simon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured