Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 111067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:19:34+00:00 2026-05-11T02:19:34+00:00

Any idea how to initialize .NET delegate that points to method from ‘mixed’ class

  • 0

Any idea how to initialize .NET delegate that points to method from ‘mixed’ class instance?

I have ‘mixed’ C++ class like this:

class CppMixClass { public:     CppMixClass(void){         dotNETclass->StateChanged += gcnew DotNetClass::ServiceStateEventHandler(&UpdateHealthState);     }    ~CppMixClass(void);    void UpdateState(System::Object^ sender, DotNetClass::StateEventArgs^ e){        //doSmth    } } 

DotNetClass is implemented in C#, and Method declaration is OK with delegate. This line generates error:

dotNETclass->StateChanged += gcnew DotNetClass::ServiceStateEventHandler(&UpdateHealthState); error C2276: '&' : illegal operation on bound member function expression 

Anyone have a clue about a problem? Maybe coz CppMixClass class is not a pure .NET (ref) class?

I got this to work when UpdateHealthState is static method, but I need pointer to instance method.

I tried smth like:

dotNETclass->StateChanged += gcnew DotNetClass::ServiceStateEventHandler(this, &UpdateHealthState); 

But this obviously doesn’t work coz this is not pointer (handle) to .NET (ref) class, (System::Object).

ServiceStateEventHandler is defined in C# as:

public delegate void ServiceStateEventHandler(object sender, ServiceStateEventArgs e); 

Thanx for reading this 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:19:35+00:00Added an answer on May 11, 2026 at 2:19 am

    I just found answer to this(of course by Nishant Sivakumar, man seems to have answers to all my C++/CLI interop related problems):

    http://www.codeproject.com/KB/mcpp/CppCliSupportLib.aspx?display=Print

    Answer is located in ‘msclr/event.h’ header, where macros for delegates in native classes are defined.

    Nish’s code is following:

    class Demo5 { msclr::auto_gcroot<FileSystemWatcher^> m_fsw; public: // Step (1) // Declare the delegate map where you map // native method to specific event handlers  BEGIN_DELEGATE_MAP(Demo5)     EVENT_DELEGATE_ENTRY(OnRenamed, Object^, RenamedEventArgs^) END_DELEGATE_MAP()  Demo5() {     m_fsw = gcnew  FileSystemWatcher('d:\\tmp');     // Step (2)     // Setup event handlers using MAKE_DELEGATE     m_fsw->Renamed += MAKE_DELEGATE(RenamedEventHandler, OnRenamed);     m_fsw->EnableRaisingEvents = true; } // Step (3) // Implement the event handler method  void OnRenamed(Object^, RenamedEventArgs^ e) {     Console::WriteLine('{0} -> {1}',e->OldName, e->Name); } }; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't even see where visitor is being used in… May 11, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer Is it related to this? http://support.microsoft.com/default.aspx?scid=KB;EN-US;q248055 Might be missing a… May 11, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer SELECT date, COALESCE(lcomm, 0), COALESCE(lcnt, 0), COALESCE(ccomm, 0), COALESCE(ccnt, 0),… May 11, 2026 at 10:44 pm

Related Questions

Any idea how to initialize .NET delegate that points to method from 'mixed' class
This question is directly related to my previous question ASP.NET AJAX Is it possible
I am having some trouble with one of my ASP.NET 2.0 application's connection string.
I'm trying to do a simple thing; read an image from the internet, save
Imagine an CoreData entity (e.g. named searchEngine ). NSManagedObjectContext manages some instances of this

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.