Call native C++ function from C#

1.8k views Asked by At

I have C++ legacy code with functions in the form:

double func(double)

I have this as a source file - it isnt in the form of a DLL although it could be turned into one if necessary

How can I call func in my C# code (maybe over managed C++)? I heard of Marshalling and DllImport but I did not find MSDN very helpful.

1

There are 1 answers

0
Klinki On

You have to compile C++ code as DLL library and then DllImport is way to go.

I don't know what problem you have with it. On MSDN I found this https://msdn.microsoft.com/en-us/library/e59b22c5.aspx

And also this article: http://www.mono-project.com/docs/advanced/pinvoke/ seems to be quite useful.