473,396 Members | 2,013 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,396 software developers and data experts.

Managed Event Question - Static Event

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 can use the interface as
preferred. How do you expose a static event through an interface?
In the example below as coded, in a VB app I can access and use the general
method (MyMethod) if I declare my handle variable as an IMyInterface type. I
can also use the general method and handle the event in VB if I declare as a
CMyClass. I cannot however seem to expose the static event through the
interface IMyInterface; any ideas?

public interface class IMyInterface
{
void MyMethod();

// delegate void EventHandler(const long lVal, bool% bVal); - WONT COMPILE
// static event EventHandler^ OnEventPost; - WONT COMPILE
};

public ref class CMyClass : IMyInterface
{
CMyClass();
~CMyClass();

virtual void MyMethod();

delegate void EventHandler(const long lVal, bool% bVal);
static event EventHandler^ OnEventPost;
};

Thanks

Mar 28 '07 #1
3 2286
In the example below as coded, in a VB app I can access and use the
general
method (MyMethod) if I declare my handle variable as an IMyInterface type.
I
can also use the general method and handle the event in VB if I declare as
a
CMyClass. I cannot however seem to expose the static event through the
interface IMyInterface; any ideas?
Should work according to:
"An interface can contain declarations for functions, events, and
properties. All interface members have public accessibility. An interface
can also contain static data members, functions, events, and properties, and
these static members must be defined in the interface."

Note "must be defined in the interface", this probably prohibits forward
declaration.
>
public interface class IMyInterface
{
void MyMethod();

// delegate void EventHandler(const long lVal, bool% bVal); - WONT
COMPILE
Have you tried without the const? Essentially const is only supported in
unmanaged code, managed types can only use literal and initonly, neither or
which are the same as const and neither of which can be applied to an
argument.
// static event EventHandler^ OnEventPost; - WONT COMPILE
};
What's the exact error message?
Mar 28 '07 #2

Thanks for your response and interest - I need the help. My mistake, it's
actually a link problem (i.e., not compile); the link errors are as follows:

Interface Assembly Link Errors:
MyInterface.obj : error LNK2020: unresolved token (0600003A)
IMyInterface::add_OnEventPost
MyInterface.obj : error LNK2020: unresolved token (0600003B)
IMyInterface::remove_OnEventPost

Implementing Ref Class Assembly Link Errors:
MyClass.obj : error LNK2020: unresolved token (0600003A)
IMyInterface::add_OnEventPost
MyClass.obj : error LNK2020: unresolved token (0600003B)
IMyInterface::remove_OnEventPost

Note the interface is in one assembly while implementing class is in another
assembly (as encouraged by interface programming guidance) thus the 2 sets of
link errors. Again this approach seems to work fine for all normal methods
and only has problems (i.e., link errors) dealing with events.

In reviewing these errors since our initial exchange, it's like I need to
define other 'stuff' just because I've now published in the interface. But
what other stuff (e.g., add, remove, raise) and what should it look like?
Again keep in mind all works fine if I use in VB directly refed as class
instead of interface.

I have tried eliminating the const specifier with no material change in
result.

Again thanks for any guidance here


"Ben Voigt" wrote:
>
In the example below as coded, in a VB app I can access and use the
general
method (MyMethod) if I declare my handle variable as an IMyInterface type.
I
can also use the general method and handle the event in VB if I declare as
a
CMyClass. I cannot however seem to expose the static event through the
interface IMyInterface; any ideas?

Should work according to:
"An interface can contain declarations for functions, events, and
properties. All interface members have public accessibility. An interface
can also contain static data members, functions, events, and properties, and
these static members must be defined in the interface."

Note "must be defined in the interface", this probably prohibits forward
declaration.

public interface class IMyInterface
{
void MyMethod();

// delegate void EventHandler(const long lVal, bool% bVal); - WONT
COMPILE

Have you tried without the const? Essentially const is only supported in
unmanaged code, managed types can only use literal and initonly, neither or
which are the same as const and neither of which can be applied to an
argument.
// static event EventHandler^ OnEventPost; - WONT COMPILE
};

What's the exact error message?
Mar 29 '07 #3

"NEW2.NET" <NE*****@discussions.microsoft.comwrote in message
news:AE**********************************@microsof t.com...
>
Thanks for your response and interest - I need the help. My mistake, it's
actually a link problem (i.e., not compile); the link errors are as
follows:

Interface Assembly Link Errors:
MyInterface.obj : error LNK2020: unresolved token (0600003A)
IMyInterface::add_OnEventPost
MyInterface.obj : error LNK2020: unresolved token (0600003B)
IMyInterface::remove_OnEventPost

Implementing Ref Class Assembly Link Errors:
MyClass.obj : error LNK2020: unresolved token (0600003A)
IMyInterface::add_OnEventPost
MyClass.obj : error LNK2020: unresolved token (0600003B)
IMyInterface::remove_OnEventPost

Note the interface is in one assembly while implementing class is in
another
assembly (as encouraged by interface programming guidance) thus the 2 sets
of
link errors. Again this approach seems to work fine for all normal
methods
and only has problems (i.e., link errors) dealing with events.
Perhaps interface static events can't be defined as trivial events. See
"How to: Define Event Accessor Methods" in the Visual C++ documentation and
provide the event implementation explicitly.
Mar 29 '07 #4

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

Similar topics

0
by: Lee Alexander | last post by:
Because of a crappy bug (which I hoped would be fixed in 7.1) I have to use an add / remove accessor for an event in a managed C++ class. The trouble is that on the C# end it won't allow me to use...
6
by: Shai Levi | last post by:
Hi, I'm trying to migrate native c++ class to managed c++ class. The native class header definition looks as: class NativeClass { public: typedef void (CbFunc1)(int n,void* p);
1
by: Bob Whiton | last post by:
I have an unmanaged class which has a member variable: gcroot<DataTable*> myDataTable; I would like to sink the RowDeleting event in my UNmanaged class. However, I can't declare an event...
0
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have...
1
by: ahmed alhamed via .NET 247 | last post by:
(Type your message here) Hi, I am trying to write a managed class tha expose Multiple Indexers Properties To C#, I use the 'DefaultMemberAttribute' Attribute, but when i use the class from C# I...
3
by: Adam | last post by:
I can't seem to find one spot on the net that specifies exactly what I need to do. Situation: Native dll needs to hold a static reference to a managed class in .net 2.0 (whidbey) which needs to...
5
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
2
by: Craig | last post by:
Hi I have a static event called PropertyChanged. PropertyChanged is a delegate called PropertyChangedEventHandler(Object^ sender, PropertyChangedEventArgs^ e) If I remove my...
0
by: Mayur | last post by:
Hello all, Im trying to call my .net c# library functions from my unmanaged vc++(dialog based MFC) application . From that application i want add the event handler for the event generated in c#...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.