472,973 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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
3 2658
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Billy Porter | last post by:
Greetings, I got a class that wraps the System.Data.SqlClient.SqlConnection class (no COM interaction). I'm not sure if I'm supposed to implement the IDisposable pattern for this wrapper or not....
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...
1
by: anders | last post by:
I call from managed C++ a DCOM server interface method that takes a callback interface as parameter. I cannot figure out how to implement such a callback object in managed C++. The callback...
15
by: Jim | last post by:
I am using VB.Net 2.0 and I am completely new to the concept of implementing interfaces. Can anyone explain "implementing interfaces" to me and perhaps give me an example of implementing an...
0
by: krzys | last post by:
After hours of browsing I can't find any hints on how to implement a COM component using a managed C++ class. In C# this is trivial, you import the interface like below and just implement it. ...
6
by: keith.thornhill | last post by:
hi all, lets say i have a usercontrol which implements a custom interface. like so: ------------------------------------------------- interface IMyInterface sub buttonClick() end interface
6
by: Smithers | last post by:
Just looking to compile a list of "all the ways to implement events". I'm NOT looking to get into the merits or mechanics of each in this thread... just want to identify them all - good, bad, and...
4
by: =?Utf-8?B?QmFqaS4=?= | last post by:
Hi, Can somebody suggest me, how can I implement a vc++ interface in C#.net. This interface has method CallMe( ) which is used as a CallBack from my main application. Thanks, Baji.
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.