クロスプラットフォームのローカルアプリ開発はC#(mono)か

Posted on 9月 23, 2008
Filed Under mac, linux, mono, クロスプラットフォーム, C++ |

「mac対応しないとか今時ねーよ」みたいなことをtypesterが言うので、調べた。

C#がいいかなぁ
What is Mono?

Mono provides the necessary software to develop and run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix

今年の3月にでたMono 1.9で
# System.Media implemented.
というのもGJ

試す
debian lennyならaptパッケージがある
System.Windows.Forms使うなら
libmono-winforms2.0-cil もお忘れなく。

まずはc#でhelloworld

C#:
  1. santrini% cat helloworld.cs
  2. using System;
  3. using System.Windows.Forms;
  4.  
  5. public class HelloWorld : Form
  6. {
  7.         static public void Main ()
  8.         {
  9.                 Application.Run (new HelloWorld ());
  10.         }
  11.  
  12.         public HelloWorld ()
  13.         {
  14.                 Text = "Hello Mono World";
  15.         }
  16. }
  17. santrini% gmcs helloworld.cs -r:System.Windows.Forms.dll
  18. santrini% export DISPLAY=localhost:51.0; mono helloworld.exe

こんな
mono

音の再生はこんな
WindowsのVisual C# 2008 Express EditionのテンプレートからつくったWindowsフォームアプリケーション。

C#:
  1. santrini% cat Program.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6.  
  7. namespace sound
  8. {
  9.     static class Program
  10.     {
  11.         /// <summary>
  12.         /// アプリケーションのメイン エントリ ポイントです。
  13.         /// </summary>
  14.         [STAThread]
  15.         static void Main()
  16.         {
  17.             Application.EnableVisualStyles();
  18.             Application.SetCompatibleTextRenderingDefault(false);
  19.             Application.Run(new Form1());
  20.         }
  21.     }
  22. }
  23. santrini% cat Form1.cs
  24. using System;
  25. using System.Collections.Generic;
  26. using System.ComponentModel;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Windows.Forms;
  30.  
  31. namespace sound
  32. {
  33.     public partial class Form1 : Form
  34.     {
  35.         public Form1()
  36.         {
  37.             WavPlayer player = new WavPlayer();
  38.             //player.play("/home/mo/tmp/csharp/sound/1.wav");
  39.             player.play("/home/mo/tmp/csharp/sound/1.mp3");
  40.         }
  41.     }
  42. }
  43. santrini% cat WavPlayer.cs
  44. using System;
  45. using System.Collections.Generic;
  46. using System.Linq;
  47. using System.Text;
  48. using System.Media;
  49.  
  50. namespace sound
  51. {
  52.     class WavPlayer
  53.     {
  54.         public WavPlayer()
  55.         {
  56.         }
  57.  
  58.         public void play(string wavfile)
  59.         {
  60.             SoundPlayer player = new SoundPlayer(wavfile);
  61.             player.Play();
  62.         }
  63.     }
  64. }
  65. santrini% gmcs Program.cs Form1.cs WavPlayer.cs -r:System.Windows.Forms.dll
  66. santrini% export DISPLAY=localhost:51.0; mono Program.exe

これはありだなぁ

Comments

2 Responses to “クロスプラットフォームのローカルアプリ開発はC#(mono)か”

  1. mash on 9月 24th, 2008 9:45

    あれれ
    http://www.mono-project.com/Mono:OSX
    A MacOS X specific Mono launcher was in development but its status is unclear today
    コマンドラインからしか起動できないの?

  2. mash on 9月 24th, 2008 14:57

    Gtk#, MonoDevelop, and System.Windows.Forms applications require X11. Installing on a machine without X11 installed will result in errors during install, and these components will not function correctly.
    だって、しかもX11があってもSystem.Windows.FormsはOSX10.5では動かないっぽい

Leave a Reply