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 8790367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:37:53+00:00 2026-06-13T22:37:53+00:00

Currently I am working with two layers. One layer is C++/CLI and the other

  • 0

Currently I am working with two layers. One layer is C++/CLI and the other layer is an unmanaged C++ graphics library that I do not have the source to. I pass data to unmanaged code and receive data back in a callback function ‘intermediateCallback’ when a user moves a manipulator in the unmanaged code.

Below is how I define the delegate type called ‘tempFunc’. It takes in nothing and returns nothing. The ‘void* userData’ parameter of ‘intermediateCallback’ is what I want to turn back into a delegate instance. This parameter is passed into the unamanged code as a delegate converted to a IntPtr cast to a void*. I can turn the void* back into an IntPtr, but how can I turn that back into a the delegate type ‘tempFunc’?

delegate void tempFunc();

//the function that the delegate instance actually points to
void libCoin3D::CenterballDragger::memberCallback()
{
....
}

//the function that the unmanaged code will call and pass data to
void intermediateCallback( void * userData, SoDragger *dragger)
{
    System::IntPtr ptr=(System::IntPtr)userData;
    tempFunc^ tF=(tempFunc^)ptr;//this line does not work, I want to do something like it
}

Originally, this is how I turned the delegate into a void* when I passed it into unmanaged code.

If tF is a delegate defined by:

tempFunc^ tF=gcnew tempFunc(this,&libCoin3D::CenterballDragger::memberCallback);

I converted it with:

(System::Void*)(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(tF))

So is it possible to convert void* into tempFunc?

  • 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-13T22:37:55+00:00Added an answer on June 13, 2026 at 10:37 pm

    I solve a similar problem like this:

    delegate void tempFunc();
    
    //the function that the delegate instance actually points to
    void libCoin3D::CenterballDragger::memberCallback()
    {
      ....
    }
    
    //the function that the unmanaged code will call and pass data to
    void __stdcall intermediateCallback( void * userData, SoDragger *dragger)
    {
      using System::Runtime::InteropServices::GCHandle;
      GCHandle gch = GCHandle::FromIntPtr((System::IntPtr)userData);
      tempFunc^ tF = (tempFunc^)gch.Target;
    
      tF();
    
      gch.Free(); // If the call only once, otherwise it is necessary to keep the pointer and delete it later     
    
    }
    
    tempFunc^ tF = gcnew tempFunc(this, &libCoin3D::CenterballDragger::memberCallback);
    
     // pass to unmanaged code
    setCallback( &intermediateCallback, (void*)GCHandle::ToIntPtr(GCHandle::Alloc(tF)) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on two social networking sites that have a lot in common,
I'm currently working with two different hashes that contain common values and I would
My problem is that the website I'm currently working on has two tables for
I am currently working on two projects in python. One need python 2.5 and
I'm currently working on two projects simultaneously: My main project (built with maven) A
Git's tab autocompletion is useful for small projects, but I'm currently working on two
I am currently working through this tutorial: Getting Started with jQuery For the two
I am currently working on a VB.Net program where there are two parallel multiline
I'm currently working on an Asp.net MVC Web application. In my solution, there're two
So, I currently am working on a project, in which two different datasources will

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.