Call c# function from within a c++ dll

Asked

Viewed 209 times

0

Situation:

  • I have a 3-layer project: One for data, one for C# and one for C++.

  • The c++ layer is made using support for clr (Common Language Runtime Support (/clr)). But I use it as wrapper between my pure C++ classes and C#. Within this layer I use VTK and ITK.

  • The C# layer makes the call to the others so it only sees the others. I need to update something that is in a form in the C# layer by going through the C++ layer. Pure C++ will call the method in the C form#.

I have already researched the subject and only found examples of how to do using socket between C# and C++. This option is not very valid for the curve I will have in the project.

For the referenced C++ I can send the form smoothly.

How can I pass the trigger from C# function to pure C++ function?

{
    FormCollection^ forms = Application::OpenForms;

    XNamespace::FormTeste^ frmTeste;

    for (int i = 0; i < forms->Count; i++)
    {
        if (forms[i]->Name == "FormTeste")
        {
            frmTeste = static_cast<XNamespace::FormTeste^>(forms[i]);
            frmTeste->GetUCCriarPanoramica()->DefinirEstadoCursorAxial(estado);
            break;
        }
    }
}

in CLR I can find the form by name, but pure C++ does not have access to this information.

  • There is, there is no problem. You are in some problem?

  • Yes, I’m unable to do this. Can you help me? With some example or direction?

  • @bigown can give me a direction?

  • Read the above, especially [Ask].

  • @bigown thanks for the tip. I’ve made the changes to be clearer.

  • You can work with events or exchange messages between the layers to indicate an action to be executed, because as you said yourself the source C++ pure does not see the code C#, only the opposite.

  • @Brunobermann this exchange would only have to be with an open c# socket and consumed by the correct c++ socket?

  • There are N ways to implement a message exchange... just use your imagination. Some examples would be the exchange for socket, for file (text, binary, etc.) or even for functions that return a string or other significant values for your implementation. In the case of functions the ideal is that it be implemented in a DLL so that all layers have access to the same communication interface. I hope I’ve helped.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.