0

I'm trying to get access to certain parts of my application through COM, mainly because I need a Delphi application to be able to invoke certain services on the .NET application.

I've managed to expose some methods via COM inheriting from ServicedComponent class and its working fine.

Now I need to be able to raise events to the client so I can alert him when certain things occur. I currently have something like this:

public interface IEvents
{
  void OnMessage();
}

[EventClass]    
[ComVisible(true)]
public class MyEventsClass : ServicedComponent, IEvents
{
  public void OnMessage()
  {
  }
}

but when I import the TypeLibrary from Delphi I get this:

IEvents = interface(IDispatch)
    ['{E7605303-F968-3509-829B-BF70084053C4}']
    procedure OnMessage; safecall;
  end;

IEventsDisp = dispinterface
    ['{E7605303-F968-3509-829B-BF70084053C4}']
    procedure OnMessage; dispid 1610743808;
  end;

which I don't really know how to use. I was expecting an IUnknown interface that I can implement and provide to the service through a MyService.Register(IEvents events)...

I think I'm completely lost here... Any advice or reference about how to properly implement COM+ events with .NET?

1 Answer 1

1

I'm still unsure of what exactly is the use for EventClass by I've discovered you don't need to use it. I simply have declared this:

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMyEventIface
{
}

And with that the interface is exported as an IUnknown interface to Delphi.

Then you define a method on your ServicedComponent class which a connect signature like this:

public void Connect(IMyEventIface eventHandler)
{
  mEvents.Add(eventHandler);
}

which left you to manually handle the invoke of each client event handler but is the only way I've found.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.