Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brett  Hall - 09 Jan 2005 01:09 GMT
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
Vladimir Nesterovsky - 09 Jan 2005 12:13 GMT
> Let's say we have a trivial VB.NET interface defined (my syntax may be
> off):
[quoted text clipped - 16 lines]
> // How implement the event here???
> }

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

Signature

Vladimir Nesterovsky
e-mail: vladimir@nesterovsky-bros.com
home: www.nesterovsky-bros.com

Brett  Hall - 09 Jan 2005 15:58 GMT
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...
Brett  Hall - 10 Jan 2005 04:11 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.