473,387 Members | 1,423 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,387 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 2683
> 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.