473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Event in interface

Anyone have an example of defining a custom event (i.e custom delegate) in an
interface?

--
Anthony Yott
Nov 18 '05 #1
4 2875
Anthony,

You mean like this:

public interface IMyInterface
{
public event EventHandler MyEvent;
}

That should give you what you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Anthony Yott" <an*********@hotmail.com> wrote in message
news:3B**********************************@microsof t.com...
Anyone have an example of defining a custom event (i.e custom delegate) in
an
interface?

--
Anthony Yott

Nov 18 '05 #2
Yes,

I didn't mention it in the post but where you have EventHandler in your
post, I need to use my own custom delegate. I was having a hard to discerning
where to define the delegate. I finally defined within the namespace and not
at class level at it worked.

Another quick question though. I have a .NET Assembly that will publish an
event and I want to subscribe to it from an MFC C++ application. Do you have
any idea if that is possible or not?

--
Anthony Yott
"Nicholas Paldino [.NET/C# MVP]" wrote:
Anthony,

You mean like this:

public interface IMyInterface
{
public event EventHandler MyEvent;
}

That should give you what you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Anthony Yott" <an*********@hotmail.com> wrote in message
news:3B**********************************@microsof t.com...
Anyone have an example of defining a custom event (i.e custom delegate) in
an
interface?

--
Anthony Yott


Nov 18 '05 #3
Nicholas,

I think the big question (for me) is how to define the delegte type for the
event in the interface so that it is availble to COM clients; otherwise I'm
not sure how the COM client can subscribe to the event if it doesn't know the
event target type.
--
Anthony Yott
"Nicholas Paldino [.NET/C# MVP]" wrote:
Anthony,

You mean like this:

public interface IMyInterface
{
public event EventHandler MyEvent;
}

That should give you what you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Anthony Yott" <an*********@hotmail.com> wrote in message
news:3B**********************************@microsof t.com...
Anyone have an example of defining a custom event (i.e custom delegate) in
an
interface?

--
Anthony Yott


Nov 18 '05 #4
Anthony,

You can't (and in most cases, shouldn't) define the delegate type for
the event ^IN^ the interface. Rather, just declare it in the same assembly,
and COM interop should pick it up just fine when creating the interop
library.

As for exporting your event for COM interop, check out the section of
MSDN titled "Exported Member Conversion", located at (watch for line wrap):

http://msdn2.microsoft.com/en-us/lib...versionanchor3

Basically, you have to define your event interface to implement in COM
to expose through connection points. However, you can't apply the
ComSourceInterfaces attribute to the interface, you have to apply it to the
class that implements the interface exposing the events.

You don't have to use COM interop in order to use the .NET component in
MFC. You could compile with /CLR, but it might give you overhead you don't
want. You could even create a shim in another MFC dll project which would
interact with .NET, and then reference that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Anthony Yott" <an*********@hotmail.com> wrote in message
news:35**********************************@microsof t.com...
Nicholas,

I think the big question (for me) is how to define the delegte type for
the
event in the interface so that it is availble to COM clients; otherwise
I'm
not sure how the COM client can subscribe to the event if it doesn't know
the
event target type.
--
Anthony Yott
"Nicholas Paldino [.NET/C# MVP]" wrote:
Anthony,

You mean like this:

public interface IMyInterface
{
public event EventHandler MyEvent;
}

That should give you what you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Anthony Yott" <an*********@hotmail.com> wrote in message
news:3B**********************************@microsof t.com...
> Anyone have an example of defining a custom event (i.e custom delegate)
> in
> an
> interface?
>
> --
> Anthony Yott


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ohad Young | last post by:
Hi, I have an interface with an event. I'd like to explicitly implement the interface by a certain class. However, I received the following error: "An explicit interface implementation of an...
2
by: Derrick | last post by:
How does one declare an event within an interface, so that every class which implements that interface must implement that event? I think I just need to specifiy the actual event as I would a...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
6
by: Charles Law | last post by:
I have a class, which implements an interface. Let's say, that the interface looks something like Public Interface IEventSinks Sub ValueChanged(sender As Object, e As ValueChangedEventArgs) Sub...
1
by: sundog2000 | last post by:
I am writing my first VB.net program and I am struggling to figure out how to attach an event to a method, when the event is part of an interface that the class implements. I have declared a...
3
by: Matt F. | last post by:
I have an abstract class that about a dozen sub-classes inherit from. I want to enforce that each sub-class shadows an event in the abstract class, but can't quite figure out how to do this. ...
3
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a static event declared in a C++ ref class, that can then be handled in a VB app. I'm trying to expose the static event through the interface that the C++ ref class implements so the VB app...
2
by: erbilkonuk | last post by:
Hi, I am very new to .NET Remoting and I try to run a simple program to subscribe to an event raised by Remoting Class. The Remoting Server initiates an instance of Remoting Class as Singleton /...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.