Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Callback function from C# to C++

$
0
0
Hello,

I have searched on the net, but I haven't found an answer to my problem.

I have a C++ program (an exe file) and a C# dll. The exe file contains a callback function. I need to send the pointer to the C# dll, in order to call the function back from C#.

Here is a scenario:

In the C++ file:

struct MSG_INFO
{
    void* caller;        
    char* info;
    long errnum;
};

void callback(MSG_INFO* info)
{
  // do something
}

The C# dll should receive the pointer to the callback function from the exe and call it through this pointer. If I use managed C++ instead of C#, everything works perfect. I use .NET 2.0 and Visual Studio 2005.

A short C# sample of how to receive the pointer to callback function and how to call the function using the pointer would be great.
Thank you for any help/advice.

Viewing all articles
Browse latest Browse all 1710

Trending Articles