Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: .NET bindings (C# form application) talking with C++ project  (Read 2626 times)

0 Members and 1 Guest are viewing this topic.

ixque

  • Newbie
  • *
  • Posts: 2
    • View Profile
I am developing with SFML on OSX, but for a level editor i want to use Windows forms, because i'm quite familiair with them. I already got my game working on Windows.

Now i tried to make a C++ Windows Form project, which would then create an SFML window with my game, but because of CLR and STD (managed/unmanaged) hating each other, things did not work out. Got a load full of linker errors.

Then i saw there were C# bindings and decided to make a C# Windows Form application. Now i got a nice SFML window all set up, but i want to run my C++ game code. Is this possible?

How can i create an instance of my game (Core.cpp for example) in my C# project?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: .NET bindings (C# form application) talking with C++ project
« Reply #1 on: May 02, 2013, 12:44:13 pm »
From what I've found on Google, .Net assemblies with native C++ inside can only work on Windows platforms, Mono doesn't support this mode.

So your only option would be to export your C++ API as C functions, and use P/Invoke to call them from your .Net program. This is what SFML.Net does, by the way.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: .NET bindings (C# form application) talking with C++ project
« Reply #2 on: May 02, 2013, 12:45:47 pm »
You could use P/Invoke. The interoperation is not trivial when combining managed and native code (for example because of object lifetimes), so depending on the code you might directly want to write it in C#.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ixque

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: .NET bindings (C# form application) talking with C++ project
« Reply #3 on: May 02, 2013, 01:12:49 pm »
Thanks for the quick reply!

Seems like a lot of work for a simple editor. Are there alternatives to this, instead of using Windows Forms. I read about the Qt framework for example? Or maybe some ideas for OSX? :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: .NET bindings (C# form application) talking with C++ project
« Reply #4 on: May 02, 2013, 01:16:47 pm »
You can also use one of the GUIs that were specifically designed for SFML: SFGUI and TGUI.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: .NET bindings (C# form application) talking with C++ project
« Reply #5 on: May 02, 2013, 03:11:31 pm »
There are many other C++ GUI libraries, but I strongly suggest Qt. It's big and can be hard to learn, but definitely worth it.
Laurent Gomila - SFML developer