[ACCEPTED]-Call C# dll function from C++/CLI-dllimport

Accepted answer
Score: 26

You must be using c++ CLI, otherwise you 10 could not call DllImport. If that is the 9 case you can just reference the c# dll.

In 8 c++ CLI you can just do as follows:

using namespace Your::Namespace::Here;

#using <YourDll.dll>

YourManagedClass^ pInstance = gcnew YourManagedClass();

where 7 'YourManagedClass' is defined in the c# project 6 with output assembly 'YourDll.dll'.

** EDIT 5 ** Added your example.

This is how your 4 example needs to look like in CLI (for clarity 3 I am assuming that G etResult is not a static 2 function, otherwise you would just call 1 Calculate::GetResult(...)

private: System::Void CalculateResult(int arg1, int arg2)
    int rez=0;
    //Call C++ function from dll
    Calculate^ calculate= gcnew Calculate();

More Related questions