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

The Archive Base Latest Questions

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

I want unmanaged C++ code to call a C# function as a callback. I

  • 0

I want unmanaged C++ code to call a C# function as a callback. I have a CLI/C++ class wrapping around the unmanaged code. An instance of this CLI/C++ class exists within the C#.

The C# code looks like the below text. I have a (delegate) function pointer to the callBack method. I have the CLI instance of CLI_class. I want to give it the function pointer somehow in the addValueChangedCallBack function.

public Setup(){
    tempFUNC myFuncObj = new tempFUNC(callBack)
    CLI_class c=new CLI_class();
    c.addValueChangedCallBack(myFuncObj)
}

public delegate void tempFUNC(float x);

void callBack(float x){
....
}

Then in the CLI code I want to do something like this:

void addValueChangedCallback(void (*ManipCallBack)(float)){
   unmanagedCPPCLASS.addValueChangedCallback(ManipCallBack)

}

How can I turn the function pointer into a C++ pointer (*)? Also, I cannot reference the C# project in the C++/CLI project because the C# class already references and uses the C++/CLI project. Will there be a dependency issue?

I have seen references on some sites to ‘marshaling data’ or using ‘interop’. I don’t understand how they work or what exactly they do from anything I have seen, are these what I should be using?

  • 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-13T11:53:48+00:00Added an answer on June 13, 2026 at 11:53 am

    You can have both projects reference each other and use System.InteropServices.Runtime.Marshal.GetFunctionPointerForDelegate to get the function pointer.

    But if I were you I’d make the C# class ComVisible and have the C++ code call the C# method directly though a COM interface. That way there’s no need for a C++/CLI wrapper. Wrappers are always a pain, as you’re experiencing. C++/CLI has its uses, but creating wrappers is not it.

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

Sidebar

Related Questions

I want to call the following function from my managed code: short LS_LoadConfig(LS_ID SensorID,LPVARIANT
I have a wrapper around a C++ function call which I call from C#
I want to call my .NET code from unmanaged C++. My process entrypoint is
We have a C++/CLI class, let us call it class A, from which we
I have two unmanaged pointers in the form of IntPtr and want to copy
Want to run javascript function from parent window in child window Example I have
I have a unmanaged DLL that exposes a function that takes a pointer to
As the title says i want to call a mixed mode assembly from unmanaged
Possible Duplicate: Best way to call Managed .NET code from Unmanaged code I'm curious
I have a managed thread which is waiting, blocked, in an unmanaged code (specifically,

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.