1

I have a C# GUI, and a dll I compiled in matlab for C++. I would like to call from my C# code to the dll functions. I tried first to convert the C# code to CLI, but then saw it is not recommended. Can I create one solution with 2 projects - one the C# GUI and one - wrap the c++ dll with C++ code and call it from the C# ?

Any reference will be appreciated.

Thanks

1

1 Answer 1

2

You can use C++ dll's in C# by using [DllImport] attribute, it is described in this MSDN thread.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, I used this, but I'm having a problem, In the dll I have a function fl(int x, arr y), where arr type is defined in a c++ header file, which is included in the dll, but it is not recognized in the C# code
@matlabit You can assign it to dynamic variable in C# and use it in the same way as in C++. dymanic keyword was introduced right to simplify inter-operational routine
Not so sure I get it, my dll function gets a type that C# cant recognize, I can compile it using dynamic, but how do I call the function ? for example: [DllImport("myDll.dll")] extern static void myfunc(dynamic a, dynamic b); now say I want to use it, how can I assign a and b ?
@matlabit dynamic are the variables behavior of which are not being checked explicitly. For example, if a and b are C++ integer arrays, Int32 aValue = (Int32)a[0] must work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.