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

  • SEARCH
  • Home
  • 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 8153067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:53:56+00:00 2026-06-06T15:53:56+00:00

Let’s assume there is a static .Net method static void RegisterDelegate(Action<array<Object^>^>^ handler); defined in

  • 0

Let’s assume there is a static .Net method

static void RegisterDelegate(Action<array<Object^>^>^ handler);

defined in some assembly we can’t modify.

I do have the following code:

static void HandleCallback(Action<array<Object^>^>^ handler, NATIVE_CPP_TYPE *nativeObject){
    //some code here
}

static void TestCall(NATIVE_CPP_TYPE *nativeObject){
    //RegisterDelegate(??);
}

where NATIVE_CPP_TYPE is some non-serializable and native-only type which can’t be modified either.

A call to TestCall(ptrToObj) should now create a delegate of type Action<array<Object^>^>. This delegate should call HandleCallback when invoked and pass both, its own argument (the Object array) and the pointer to the native Object which was originally passed the the TestCall function. Therefore the pointer needs to be stored in some kind of closure.

Do you have any idea how this can be done? I thought about the System::Linq::Expressions namespace, but afaik I can’t encapsulate native objects in that kind of expression.

Thanks in advance!

  • 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. Editorial Team
    Editorial Team
    2026-06-06T15:53:57+00:00Added an answer on June 6, 2026 at 3:53 pm

    As far as I know, in C++/CLI you can’t do managed lambdas. Of course, you can just create your own class that stores the native type and then exposes a method to be used as the delegate:

    public ref class ManagedClass
    {
        static void RegisterDelegate(Action<array<Object^>^>^ handler)
        {
    
        }
    };
    
    class NATIVE_CPP_TYPE
    {
    
    };
    
    static void HandleCallback(array<Object^>^ handler, NATIVE_CPP_TYPE *nativeObject)
    {     
        //some code here 
    }  
    
    public ref class HandleCallbackWithNativeType
    {
        NATIVE_CPP_TYPE * m_pNativeObject;
    
    public:
        HandleCallbackWithNativeType(NATIVE_CPP_TYPE *nativeObject)
        {
            m_pNativeObject = nativeObject;
        }
    
        void Execute(array<Object^>^ array)
        {
            HandleCallback(array, m_pNativeObject);
        }
    };
    
    
    static void TestCall(NATIVE_CPP_TYPE *nativeObject)
    {
        // This type will act as your closure "capturing" nativeObject.
        HandleCallbackWithNativeType ^ pHandler = gcnew HandleCallbackWithNativeType(nativeObject);
        Action<array<Object^>^>^ handler = gcnew Action<array<Object^>^>(pHandler, &HandleCallbackWithNativeType::Execute);
    } 
    

    It’s not as convienent as the lambda syntax, but it does the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say there is a graph and some set of functions like: create-node ::
Let's assume that a user votes for some movies in a scale of 1
Let's say we have this code: <form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='userFile'><br> <input
Let's say I have a method in java, which looks up a user in
Let's say I can call a method like this: core::get() . What is the
Let's assume that we are building a high traffic site that will be used
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let assume we have two activities. A - main activity, that is home launcher
Let's say you have a method that expects a numerical value as an argument.
Let's say I have the string: hello world; some random text; foo; How could

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.