Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
VB
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 code:

C#
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();
      }
   }
}


Simple app in WinForms:
C#
dllTest.MyClass mc = new dllTest.MyClass();
mc.Test();
Posted
Updated 27-Aug-14 4:56am
v3
Comments
CB Sharma 27-Aug-14 10:14am    
Hello

Once you build project onx86 bit and try
kjon4200 27-Aug-14 10:32am    
Building on x86 bti doesn't work.
Sergey Alexandrovich Kryukov 27-Aug-14 11:24am    
Does it happen when you running application under .NET, or Mono for Windows?
How do you want to use it?
The problem is: GAC for Mono is different from the GAC for .NET on the same system...

But your problem looks different. This exception... on what line?
...Or, I did not notice that you solved the problem already.

—SA

1 solution

Problem solved.
My solution is very simple:

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


Two lines of code and everything works fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900