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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:03:58+00:00 2026-05-15T01:03:58+00:00

I am really confused by the multitude of misinformation about native / managed interop.

  • 0

I am really confused by the multitude of misinformation about native / managed interop.

I have a regular C++ exe which is NOT built using CLR stuff (it is neither Managed C++ nor C++/CLI and never will be). This C++ exe is “in charge”, there is no managed wrapper for it.

I would like to access some code I have in a C# assembly from my C++ exe. I can access the C# assembly from my C++ code using COM. However, when my C# code detects an event I would like it to call back into my C++ code. The C++ function pointer to call back into will be provided at runtime. Note that the C++ function pointer is to a function found in the exe’s execution environment. It may use static members from there. I don’t want the managed code to try and load up some DLL to call a function (there is no DLL).

How do I pass this C++ function pointer to my C# code through COM/.NET and have my C# code successfully call it?

Thanks!

  • 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-05-15T01:03:59+00:00Added an answer on May 15, 2026 at 1:03 am

    You’ll probably want to use Marshal.GetDelegateForFunctionPointer:

    1. Create a delegate type that matches the signature of the native function, keeping in mind the right way to marshal types and using MarshalAs as needed
    2. Communicate the native function pointer from your native code to your C# code however you can (in your case, it looks like you can use your COM -> C# connection)
    3. Use Marshal.GetDelegateForFunctionPointer to turn the pointer into a C#-callable delegate
    4. Invoke the delegate with your parameters

    Junfeng Zhang has an example of doing this here.

    Note the restrictions mentioned on MSDN:

    The GetDelegateForFunctionPointer
    method has the following restrictions:

    • Generics are not supported in interop
      scenarios.
    • You cannot pass an invalid function
      pointer to this method.
    • You can use this method only for pure
      unmanaged function pointers.
    • You cannot use this method with
      function pointers obtained through C++
      or from the GetFunctionPointer method.
    • You cannot use this method to create a
      delegate from a function pointer to
      another managed delegate.

    The part about C++ is likely referring to function pointers for class methods. This should still work for global functions.

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

Sidebar

Related Questions

I`m really confused here about this weird behavior! The thing is, I have a
I'm really confused about OpenGL's modelview transformation. I understand all the transformation processes, but
I'm really confused. I have the following html in a form: <input class=check-box id=Data__Correct
I'm really confused as to why my URL dispatcher is not matching this url
I'm really confused about UTF in Unicode. there is UTF-8, UTF-16 and UTF-32. my
I am bringing out a separate question from here . It really confused me.
I am really confused with this one. Here's my code class inner { var
I got really confused with static and non-static functions and class properties when I
I'm really confused as to what's going on below. If I just try and
I got really confused of all the W3C specifications and implementations of different browsers.

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.