如何在Windows Forms项目中使用Mono中的dll? [英] How to use dll from Mono in Windows Forms project?

查看:94
本文介绍了如何在Windows Forms项目中使用Mono中的dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Visual Studio中的WinForms中使用Mono(GTK)编译的简单dll。

我在VS中添加了对gtk-sharp,Mono.Cairo / Posix,gtk-dotnet的引用,atk-sharp



我开始使用单声道,在我继续处理单声道更重要的事情之前我必须确保写入的dll mono,将与Visual Studio中的其他项目一起使用。有人会给出一个代码示例,它会在WinForms中打开一个windows / dilalog吗?

当我运行我的代码时,我收到一个错误:

I would like to use simple dll compiled in Mono(GTK), in WinForms in Visual Studio.
I added references in VS to gtk-sharp, Mono.Cairo/Posix, gtk-dotnet, atk-sharp

I'm starting to work with mono and before I proceed to work on more important things in mono I have to make sure that the dlls written in mono, will work with other projects in Visual Studio. Could someone give an example of code that will open a the windows/dilalog in WinForms?
When I'm running my code, i get an error:

System.AccessViolationException was unhandled
  HResult=-2147467261
  Message=Attempted to read or write protected memory. Often, this indicates that the other memory is corrupt.
  Source=gtk-sharp
  StackTrace:
       w Gtk.Dialog.gtk_dialog_run(IntPtr raw)
       w Gtk.Dialog.Run()
       w dllTest.MessageBox.Show(String Msg)
       w dllTest.MyClass.Test()
       w AllegroParser.Form1.Form1_Load(Object sender, EventArgs e) w C:\Users\KrzysiekJ\Documents\Visual Studio 2010\Projects\AllegroParser\AllegroParser\Form1.cs:wiersz 23
       w System.Windows.Forms.Form.OnLoad(EventArgs e)
       w System.Windows.Forms.Form.OnCreateControl()
       w System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       w System.Windows.Forms.Control.CreateControl()
       w System.Windows.Forms.Control.WmShowWindow(Message& m)
       w System.Windows.Forms.Control.WndProc(Message& m)
       w System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       w System.Windows.Forms.ContainerControl.WndProc(Message& m)
       w System.Windows.Forms.Form.WmShowWindow(Message& m)
       w System.Windows.Forms.Form.WndProc(Message& m)
       w System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       w System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       w System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)





Dll代码:





Dll code:

namespace dllTest
{
   public class MyClass
   {
      public MyClass ()
      {
      }
      public void Test ()
      {
         MessageBox.Show ("test");
      }
   }
   public class MessageBox
   {
      public static void Show(string Msg)
      {
         MessageDialog md = new MessageDialog (null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Msg);
         md.Run ();
         md.Destroy();
      }
   }
}





WinForms中的简单应用:



Simple app in WinForms:

dllTest.MyClass mc = new dllTest.MyClass();
mc.Test();

推荐答案

问题解决了。

我的解决方案非常简单:



Problem solved.
My solution is very simple:

Gtk.Application.Init();
dllTest.MyClass mc = new dllTest.MyClass();
mc.Test();
Gtk.Application.Run();





两行代码,一切正常。



Two lines of code and everything works fine.


这篇关于如何在Windows Forms项目中使用Mono中的dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆