如何在Windows Forms项目中使用Mono中的dll?

编程入门 行业动态 更新时间:2024-10-26 20:23:55
本文介绍了如何在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?

本文发布于:2023-10-07 10:29:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   如何在   Windows   Forms   Mono

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!