C# Remoted Event Source, COM Event Sink

dotnet framework

    Next

  • 1. Problem: Control calls IUnknown not IDispatch on container
    I've built a .Net control and wrappered it for ActiveX/COM Interop. The Type Library looks fine (almost identical to one from a working C++ control) and it is created correctly in a C++ ActiveX control container. I can call functions on the control but handling events in the container does not work. The C++ control, which behaves correctly, calls QueryInterface (after the Container calls ConnectionPoint->Advise()) for its own IDispatch interface and then calls Invoke when it fires an event. The .Net control calls QueryInterface for its IDispatch but then calls it again for an IUnknown interface using the same pointer variable it used for the IDispatch one (so it is overwritten?). When the event is fired from the control, it appears that it is attempting to use the IUnknown style because it calls GetIDsForNames and does not call Invoke. Of course I can't step through the CLR when debugging. Have I missed something or does .Net need an IUnknown pointer for something and I need to do something drastic to the container? The only clue I have is that my interfaces in the Type library for the new control have a "custom" keyword with uuids but I can't see how to stop them from being generated. TIA
  • 2. Outlook PropertyPageSite
    How do I get the PropertyPageSite object in an AddIn. I have tried bot the Parent Property and Site Property of the C# UserControl to no Avail ???
  • 3. try to instanciate my c# .net class from a c++ com component, it work in xp ... not in 2000
    Hello, try to instanciate my c# .net class from a c++ com component .. these 2 composants are deployed on a network ... (5 XP computers and 5 2000 Computers) instancation work on XP In 2000 system, Com object receive com_error : "class not registred" (i have ever try to add manualy my dotnet dll in assembly configuration) an idea to debug ???
  • 4. Public .Net method not visible in COM app
    I followed MSDN examples to create a .Net component library and a CCW for it. I then proceed to use the CCW in a VB6 app. I see the .Net library listed as a reference in the VB 6 project, I can include that reference and instantiate that object. However, none of the public methods in the .Net component are visible to the VB app. What am I missing Thanks in advance SUN.

C# Remoted Event Source, COM Event Sink

Postby Tim » Thu, 22 Sep 2005 00:58:51 GMT

Hi All,

I'm having trouble figuring this out. I have a C# object, which is
exposed to COM, and fires events. I also have a COM object that can
create the C# object, call DispEventAdvise to be the sink for these
events. This all works fine. Now I want to change it so that instead of
the COM object CoCreating the C# object, I have a C# server which
remotes the object. The COM object uses Activator::GetObject() to get
the remoted object, and then I want to call DispEventAdvise() to set
the COM object as an event sink for the remoted object. I can't get it
to work. DispEventAdvise returns hr = 0x8013150B. I'm assuming that
this should be possible, and help would be greatly appreciated.

My C# object...

using System;
using System.Runtime.InteropServices;

namespace EventSource
{
	public delegate void OnCompleteDelegate();

	// Define event sink interface to be implemented by the COM sink
	[GuidAttribute("7D6A6BB0-C136-4a22-9F84-ABC8603B3D6F") ]
	[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
	public interface IEventTestEvents
	{
		[DispId(0)] void OnComplete();
	}

	[GuidAttribute("88A158C1-896C-467a-B3CC-9F2068093AE2") ]
	[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
	public interface IEventTest
	{
		void FireCompleteEvent();
	}

	// Connects the event sink interface to a class
	[ComSourceInterfaces(typeof(IEventTestEvents))]
	[ClassInterface(ClassInterfaceType.None)]
	public class EventTest : MarshalByRefObject, IEventTest
	{
		// URL information for remoting this object
		public const String RemotingProtocol = "tcp://";
		public const String RemotingPort = "1234";
		public const String RemotingURI = "EventTestUri";
		public const String RemotingLocal = RemotingProtocol + "localhost" +
":" + RemotingPort + "/" + RemotingURI;
		public const String RemotingRemote = RemotingProtocol + "{0}" + ":" +
RemotingPort + "/" + RemotingURI;

		public event OnCompleteDelegate OnComplete;

		public EventTest()
		{
		}

		public void FireCompleteEvent()
		{
			OnComplete();
		}
	}
}


The code in my COM object where I try to call DispEventAdvise...

EventSource::EventTest* et =
static_cast<EventSource::EventTest*>(System::Activator::GetObject(__typeof(EventSource::EventTest),
EventSource::EventTest::RemotingLocal));
	System::IntPtr iUnknown =
System::Runtime::InteropServices::Marshal::GetIUnknownForObject(et);
	IUnknown* pUnk = (IUnknown*)(void*)iUnknown;
	HRESULT hr = DispEventAdvise(pUnk, &DIID_IEventTestEvents);

Thanks for any help,

Tim.


Similar Threads:

1.Problem with Event sink (ATL C++) when the event source is a C# object

Hello everybody,

I need to send from a C# object events, that have to be caught
in my C++ code. I have followed the instructions from the MSDN article
"Raising Events Handled by a COM Sink", but I have a problem
when I call AtlAdvise in the C++ client: the method FindConnectionPoint
will fail with error CONNECT_E_NOCONNECTION (0x80040200).

So I suppose there is a problem with the connetion point map. I found
in another posting that the event instance name has to be the same as the
interface method, which I did, but with no result.

How can I solve my problem? Stupid ideea: is there any way to define 
(correct)
manually the message map for the C# object, like it was possible in C++?

Many thanks for your help,
Cristian





2.Problem with Event sink (ATL C++) when the event source is a C# ob

Sorry, I forgot to mention that I am an MSDN subscriber, so I would
be pleased to see some "Microsoft" answers.

Regards,
Cristian Marinescu


"Cristian Marinescu" wrote:

> 
> Hello everybody,
> 
> I need to send from a C# object events, that have to be caught
> in my C++ code. I have followed the instructions from the MSDN article
> "Raising Events Handled by a COM Sink", but I have a problem
> when I call AtlAdvise in the C++ client: the method FindConnectionPoint
> will fail with error CONNECT_E_NOCONNECTION (0x80040200).
> 
> So I suppose there is a problem with the connetion point map. I found
> in another posting that the event instance name has to be the same as the
> interface method, which I did, but with no result.
> 
> How can I solve my problem? Stupid ideea: is there any way to define 
> (correct)
> manually the message map for the C# object, like it was possible in C++?
> 
> Many thanks for your help,
> Cristian
> 
> 
> 
> 
> 
> 

3.Exception Raising Events from C# DLL (COM Event Source) to Excel V

4.Managed event source, unmanaged event sink

Hi, I am using .NET Framework 2.0 with Visual Studio 2005 Beta Professional. 
Here is the deal: Currently I have a managed class "A" (located ina C# class 
library) that has a few custom events. An unmanaged C++ class "B" has a 
member variable of type "A". Can class "B" directly receive the events of 
class "A", and if so how (code examples)? What I mean by "directly" is can 
one write code like: 
m_ManagedObject->EventOccurred += gcnew EventOccurred(this, 
&UnmanagedClass::EventOccurred);
without having to use some intermediary managed class that receives the 
events and then calls the appropriate function of the unmanaged object?
Thanks for looking, Mario

5.Attaching Event Sink to Event Source

Hi,

            I have custom event class defined named "CustomEvent". Also I 
have a defined a custom sink named "CustomSink" derived from Eventsink. I 
want tthat Write method the Custom Sink should be called when I raise the 
evet using EventSource method.

Code:-

CustomEvent custEvt = new CustomEvent ( );
EventSource eventSource = new EventSource( "source1" );
eventSource.Raise( custEvt );


But the Write method is not getting called.

Can any please tell me how to attach the sink with the event source.

Thanks,
Reshma 


6. Event Handling with VB6 source / C# sink

7. C# com and c++ event sink

8. Catching C# generated events with an ATL COM Sink



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 55 guest