2012-07-05 93 views
12

我一直試圖讓GTK#​​在Windows Server 2008 R2 x64上的Visual Studio 2010中工作,以便我可以開始編寫漂亮的跨平臺GUI應用程序,但我有點新到C#,我遇到了一個麻煩的世界。在Visual Studio 2010中的GTK#

我安裝了包含GTK#的Windows最新Mono。我還安裝了一個Mono 2.10.8配置文件作爲我的項目的目標框架,鬆散地遵循以下指南:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/

我創建了一個新的Windows窗體應用程序,並刪除了對Windows窗體的引用並添加了GTK#從這裏鬆散地遵循指南:http://jrwren.wrenfam.com/blog/2008/11/01/gtk-in-visual-studio-2008-on-vista-x64/

我還添加了對gtk-dotnet的引用以及來自該指南的引用。

這是我的應用程序的完整代碼:

using System; 
using System.Runtime.InteropServices; 
using System.Collections.Generic; 
using System.Linq; 
using Gtk; 

namespace GridToGo 
{ 
    static class Program 
    { 
     [STAThread] 
     static void Main() 
     { 
      Application.Init(); 
      Window myWin = new Window("My first GTK# Application! "); 
      myWin.Resize(200, 200); 
      myWin.Destroyed += new EventHandler(myWin_Destroyed); 
      Label myLabel = new Label(); 
      myLabel.Text = "Hello World!!!!"; 
      myWin.Add(myLabel); 
      myWin.ShowAll(); 
      Application.Run(); 
     } 

     static void myWin_Destroyed(object sender, EventArgs e) 
     { 
      Application.Quit(); 
     } 
    } 
} 

當我嘗試使用任何配置下運行,我得到以下異常:

System.TypeInitializationException was unhandled 
    Message=The type initializer for 'Gtk.Application' threw an exception. 
    Source=gtk-sharp 
    TypeName=Gtk.Application 
    StackTrace: 
     at Gtk.Application.Init() 
     at GridToGo.Program.Main() in F:\visual-studio\GridToGo\GridToGo\Program.cs:line 13 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: System.DllNotFoundException 
     Message=Unable to load DLL 'glibsharpglue-2': The specified module could not be found. (Exception from HRESULT: 0x8007007E) 
     Source=glib-sharp 
     TypeName="" 
     StackTrace: 
      at GLib.Thread.glibsharp_g_thread_supported() 
      at GLib.Thread.get_Supported() 
      at Gtk.Application..cctor() 
     InnerException: 

我無法弄清楚如何獲得它找到該DLL!我甚至嘗試將4個副本的DLL複製到解決方案中的幾乎每個文件夾中,並使用以下名稱:glibsharpglue-2glibsharpglue-2.dllglibsharpglue-2.oglibsharpglue-2.o.dll!我甚至還嘗試從GTK站點安裝GTK一體化軟件包,並將其bin文件夾添加到我的系統路徑中,然後將相同的4個DLL複製到該文件夾​​中,所有這些都沒有運氣。

對於我瘋狂的問題有什麼建議嗎?我覺得我在這裏錯過了一些很大的東西。 > _ <

回答

19

我想通了!單聲道的Windows是完全沒有必要的。 GTK#for .NET是我所需要的。對於未來想建立自己的Windows環境下的跨平臺GTK#開發的人,這裏是我遵循的步驟:

  1. 與方向從這裏安裝Mono項目目標:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/
  2. 安裝GTK#爲來自Mono官方下載網站的.NET。
  3. 安裝Glade/GTK + for Windows,sourceforge項目在這裏:http://sourceforge.net/projects/gladewin32/
  4. 創建一個新的針對Mono的C#項目。
  5. 從您安裝GTK#for .NET的位置爲您的項目引用必要的程序集。
+1

儘管Mono的Windows.Forms支持跨平臺並不是那麼簡陋... – ruffin

+0

感謝您回來並解釋! – heltonbiker

+0

我很好奇,你爲什麼想要單聲道?使用Microsoft的Visual C#編譯器有問題嗎?如果事情足夠兼容,我會認爲無論是Mono還是Microsoft的編譯器都可以生成可以在Mono的運行時或Microsoft的.NET運行時上運行的二進制文件。 –