0

I have a C# exe and some vc++ dll's . I am creating a callBackFunction in C# whichh takes structure as its Parameters. My c++ dll will fill this structure and return it back.But 95% of the time My Exe crashes. My dll is multi threaded and my C# has backgroundWorker in it. I have put try catch block to check if any exceptions are coming or not but no exception is being caught. Can any one suggest a better way to send data from my vc++ dll to c# exe

1
  • 1
    You need to put in example code. There are a number of different ways of passing parameters and handling C++ callbacks, any of which can go horribly wrong if done incorrectly. Be aware also that in spite of what the documentation says, .NET has a habit of garbage collecting managed thunks out from under C++. Commented Feb 18, 2010 at 14:20

2 Answers 2

1

this must work:
(c#)

namespace Test
{
    public class CallbackClass
    {
        public void Callback(string s)
        {
            MessageBox.Show(s);
        }
    }
}  

(c++/cli)

...
Test::CallbackClass::Callback(gcnew System::String("woof!");
...
Sign up to request clarification or add additional context in comments.

Comments

0

If you want you could implement a COM Interface, and then you could call the methods from that interface from any .Net client.

Basic example of implementation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.