467,879 Members | 1,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

How implement VB.NET interface event in managed c++?

I have a VB.NET interface that my managed C++ code is to implement. I
seem to
be stuck implementing an event defined in that interface. Does anyone
have a
simple code snippet that will show me the basics of what I need to
implement?
I've seen all the MSDN articles on implementing events in managed C++
and
I've gotten events to work without issue when implementing all the
constructs
myself. I fail miserably when trying to correctly implement an event
defined
in a VB.NET interface. It's not clear what's defined implicitly and
explicitly. I need your help.

Let's say we have a trivial VB.NET interface defined (my syntax may be
off):

Public Interface ISomethingTrivial
Sub Func1()
Event Loaded()
End Interface

On the managed C++ side I would have:

__gc class MySomethingTrivial : public ISomethingTrivial
{
public:
// Constructor
// Destructor

void Func1() { /* Do something here */ }

// How implement the event here???
}

If I go ahead and implement the add_EventName() remove_EventName()
events I
get errors about multiple methods being defined. So I get the gist that
these
are created "behind the scenes" for me at compile time. I don't know
how to
define the raise_EventName() appropriately as I don't know what else is
under
the covers that I need to call. Each time I attempt to implement the
event
(incorrectly) I can successfully compile my managed C++ class, but when
I go
to instantiate an instance of it in my VB code I get "Cannot call New
on a
class listed as MustOverride". I assume I will see this until I
correctly
implement the event. Someone out there must have experience with
this....

Many thanks for your help. - Brett

Nov 17 '05 #1
  • viewed: 2309
Share:
3 Replies
> Let's say we have a trivial VB.NET interface defined (my syntax may be
off):

Public Interface ISomethingTrivial
Sub Func1()
Event Loaded()
End Interface

On the managed C++ side I would have:

__gc class MySomethingTrivial : public ISomethingTrivial
{
public:
// Constructor
// Destructor

void Func1() { /* Do something here */ }

// How implement the event here???
}

Did you try
__event void Loaded() { ... }

--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Nov 17 '05 #2
Thanks for the reply.

What do I call in { ... } to ensure clients that subscribed to the
event get the event? That's what I don't get. What do I call Invoke()
on to ensure subscribers of the event get the event? Is there a
delegate defined "under the covers" for me? This is where I'm lost.
Asking the question another way, is there a way to view my precompiled
header or class or whatever with the "under the covers" stuff shown?
Let me know if I'm still not making sense...

Nov 17 '05 #3
After some more experimenting tonight I have the answer for the example
above.

__gc class MySomethingTrivial : public ISomethingTrivial
{
public:
// Constructor
// Destructor

void Func1()
{
// Do stuff
Fire_Loaded();
}

virtual __event LoadedEventHandler *Loaded;
void Fire_Loaded()
{
Loaded();
}
};

Many Thanks. Brett

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Billy Porter | last post: by
3 posts views Thread by Ohad Young | last post: by
reply views Thread by krzys | last post: by
6 posts views Thread by Smithers | last post: by
4 posts views Thread by =?Utf-8?B?QmFqaS4=?= | last post: by
8 posts views Thread by John | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.