Using OF from C#?

hi

recently i had to learn C# for a project in my work and i found it to be a nice language, I have been working with Python the last years and for example I dont like Java too much, I preffer C/C++ actually, but C# feels somehow like in between Python and Java. Last week I noticed in my work that C/C++ dlls can be used within C# project. I am not sure yet how this works because i did not have the time to actually look into it properly, we just used some C# project where i noticed there where some C++ dlls.

This week i am teaching a workshop away from normal job so i had time to think again about OF and the idea to use it from C# came to my mind. I have searched the net and I found for example this link

http://www.codeproject.com/KB/cs/usecdlllibincs.aspx

it does not sound too difficult, could anyone comment on this please? i am dont know much C/C++ so maybe i am being too optimistic?? I think this could be really cool.

thanks

enrike

yes, .NET supports executing what they call non-managed code from managed code, c++ normal libraries or assemblies from any c# application, you need to do some special things with destructors and things like that but apart from that it should be possible. You will need to compile oF from visual studio as a library and then make calls to it from c#.

i work with CodeBlocks on windows, I guess it is the same, just compile it and thats it. how about Linux and OSX? i guess it would be pretty similar. Compile and use from C#…

mmh it’s not that simple, visual studio usually has problems with libraries compiled with other compilers. for osx and linux there’s mono an open source clone of the .net platform, but not sure it supports non-managed code

i guess it sound too easy to be true. thanks

just had some time to think about this again, and I found this on wikipedia

http://en.wikipedia.org/wiki/Mono-(software#Managed_and_unmanaged_code

looks to me like it would be possible to do, isnt it? But i am not sure how hard and if it is worth the effort.

Arturo podrías indicarme cómo se hace ??, siempre he querido manejar OF con C#, hasta donde había visto y conocido sólo se podía con C++ y sobre .Net hace poco, pero ahora veo según es posible… Ya quiero probar, he hecho cosas interesantes con el SDK del kinect de microsoft y me gustaría complementarlo en la parte gráfica con OF.

Can u please be more specific and explain it with an example … i really would love it if i could use Openframeworks from C# … cheers…!

Yes, this can be made to work and you can call functions written in C++ from C#. The concept is called P/Invoke to invoke unmanaged code from managed code.

You’ll probably have to modify the C++ files a little bit to add ‘extern’ identifiers to functions which will prevent name mangling and your compiler will export the functions with the same name. This is necessary when .NET tries to invoke C++ functions to call the functions specifying the same names. [DllImport in C# and do call to a C++ function]
You can either use .dll (or libs with .def if I remember correctly) in which you’ll have to explicitly call entry point functions (dll don’t have entry points unlike exes) for doing your openFrameworks operations.
There are more number of ways for achieving this using Marshalling in C# as well but I don’t have any experience with the Marshalling stuff.

There are copious examples on MSDN about P/Invoke which can help you get started.

_
Cheers
Harpreet
_

Hi All

I’m new to OF. The docs look fantastic to a noob like me. I wanted to explore more on this C# topic. I am working on an intel mac env with XCode so it’s a nice fit so far.

Can someone explain to me how to package OF libs as private ? I saw online some examples of putting your.dylibs in bundles. Can I bundle libs that are in the form of your.a? I would like to write wrapper classes to use OF with OSX and iOS for C#.

On this site I see some great examples of getting started with OF on Xcode but I don’t know much about how to make an OF application more portable. When writing plugins I’d like to avoid copying libs to /usr/local/libs if you know what I mean. So any tips would be greatly appreciated. Thanks.

Also I understand OF is made up of several components I’d like to focus on the parts that exclude the Graphics / UI (e.g. no glut or window managers). Thanks.

Create C# Binding through SWIG

1 Like