0

Hi I am trying to implement an FEM software into C# to build a GUI around it. Unfortunately I am not a c++ programer and all my software runs in c#. I thought it would be quite easy to do that, but the software I wanted to import is not a DLL, but an include(.h).

So is there any more or less easy way to implement c++ libraries in c#, to name them I am talking of these FEM open-source products - www.ofeli.org and www.oofem.org.

Thanks in advance.

DerBenutzer
  • 311
  • 1
  • 5
  • 20
  • Build the C++ project into a DLL first ... ? – Shark Feb 22 '16 at 09:24
  • @Shark Probably more complex than that. Depending on how it is written (if they are C++ classes), he will have to write a shim in C that calls the C++ methods. – xanatos Feb 22 '16 at 09:25
  • @Shark *Based on a long experience in the development of finite element software, OFELI (Object Finite Element LIbrary) is **a framework of C++ classes*** – xanatos Feb 22 '16 at 09:26
  • He has C++ sourcecode that he wants to use in C#, and that's just not going to happen @xanatos but perhaps I'm missing your point. – Shark Feb 22 '16 at 09:30
  • @Shark My point is that even compiling it in a DLL won't solve anything. You can't easily call a C++ DLL from C#. You would have to shim all the C++ methods with `extern C` methods, then shim the constructor and the destructor. – xanatos Feb 22 '16 at 09:32
  • Some possible solutions: http://stackoverflow.com/a/935713/613130 . There is even a deleted answer that suggests using SWIG to auto-generate the wrapper. – xanatos Feb 22 '16 at 09:33
  • @Xanatos ah, I see your point now. Somehow I thought C# wouldn't behave like that due to MSIL, but it looks like [THIS](http://stackoverflow.com/questions/16332701/how-to-call-c-dll-in-c-sharp) answer has the answer to this question as well. EDIT: ah, `extern C` is used to bypass C++ name mangling... got it now :) – Shark Feb 22 '16 at 09:34
  • Would it not be possible to import it as an dll and use Pinvoke in c#? I just do not know how I can easily conver the whole ofeli project in a dll. is that even possibly? – DerBenutzer Feb 22 '16 at 09:47
  • @DerBenutzer No. The easiest solution is to use C++/CLI to create a dll. You can't directl call a C++ function, even if it is in a DLL. You can't "`new SomeCPlusPlusClass()`" from C#. – xanatos Feb 22 '16 at 10:09
  • Okay that seems to be rather complicated in case of OFELI, since it uses many different header files etc.. Or would it be enough to converto the main header file in a dll, which then includes all the other .h files? – DerBenutzer Feb 22 '16 at 10:51

0 Answers0