Events from a COM source 
Author Message
 Events from a COM source

Can anyone help me figure out how to receive events from a
COM source.  I see code samples on how to do in the help
(Handling Events Raised by a COM Source  [C#]) but mine
won't compile.

Here is the situation:

CoClass Editor
Default interface: IUnknown
Outbound interface: IEditEvents

Using ILDASM I have verified the new assembly (TlbImp) has
the delagate declared properly.  Here is the code that
fails:
...
IEditEvents_OnSelectionChangedEventHandler EditorEvents =
new IEditEvents_OnSelectionChangedEventHandler
(MyOnSelectionChanged);

IEditEvents pEditorEvents = m_pEditor as IEditEvents; //QI

pEditorEvents.OnSelectionChanged += new EventHandler
(this.MyOnSelectionChanged);
...

    private void MyOnSelectionChanged()
    {
      Console.WriteLine("Dude");
    }

Error message:

IEditEvents.OnSelectionChanged()' denotes a 'method' which
is not valid in the given context

Thanks for any help,

Steve



Tue, 02 Mar 2004 00:53:59 GMT  
 Events from a COM source
oops, I posted the wrong line of code

{
IEditEvents_OnSelectionChangedEventHandler EditorEvents =
new IEditEvents_OnSelectionChangedEventHandler
(MyOnSelectionChanged);

IEditEvents pEditorEvents = m_pEditor as IEditEvents; //QI
//pEditorEvents.OnSelectionChanged += new EventHandler
(EditorEvents);

//I've tried it both ways
pEditorEvents.OnSelectionChanged += EditorEvents;

Quote:
}



Tue, 02 Mar 2004 01:33:10 GMT  
 Events from a COM source
could you rewrite the email with the correct code?

Quote:
> oops, I posted the wrong line of code

> {
> IEditEvents_OnSelectionChangedEventHandler EditorEvents =
> new IEditEvents_OnSelectionChangedEventHandler
> (MyOnSelectionChanged);

> IEditEvents pEditorEvents = m_pEditor as IEditEvents; //QI
> //pEditorEvents.OnSelectionChanged += new EventHandler
> (EditorEvents);

> //I've tried it both ways
> pEditorEvents.OnSelectionChanged += EditorEvents;
> }



Tue, 02 Mar 2004 20:42:44 GMT  
 Events from a COM source
I'm a lot closer:

private esriCoreNet.Editor Editor = null;

{
//Declare the delegate
IEditEvents_OnSelectionChangedEventHandler EditEvents =
new IEditEvents_OnSelectionChangedEventHandler
(OnSelectionChanged);

//HERE IS THE PROBLEM, ALWAYS COMES BACK NULL
//Hook the delegate to the Editor object
Editor = m_pEditor as Editor;

Editor.OnSelectionChanged += EditEvents;

Quote:
}

The onlime sample uses 'new' to create a new object, I
need to establish my sink with an object already exsiting,
one I have a reference to (IEditor).  You'd think I could
just cast but it always comes back null.

Thanks,

Steve



Wed, 03 Mar 2004 05:20:40 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Event source and sink for COM without ATL or MFC

2. ATL DLL event sink with a VB ActiveX DLL event source

3. ATL COM Component firing events into VBScript event sink

4. HELP: COM events and Network events

5. Event Sink for a COM object which raises events - Proof of Concept

6. Enable COM clients call methods inside COM events

7. How to declare com object as an event source and an event receiver (ATL7)?

8. Create Source On Remote Event Log

9. Sources on event driven programming using C?

10. Problem sinking event from 2nd source

11. IHTMLDocument2 as a event source interface.

12. IHTMLDocument2 as a Event source interface...?

 

 
Powered by phpBB® Forum Software