[Mono-dev] Fix for using GTK# in mono embedded application

Vardar Sahin sakirsoft at gmail.com
Sat Nov 2 20:42:14 UTC 2013


Hey monodev fellows,

first of all I appreciate all your hard work and want to contribute this to
the mono project.

Right now it is not possible to use GTK# with an application which embeds
mono. GTK# works just fine if you use mono as a standalone application eg
mono.exe.

The reason why GTK# does not works when you embed mono is as fallowing.

Each GTK# Application has to call Application.Init().

This functions is like this.

public static void Init ()
{
SetPrgname ();
IntPtr argv = new IntPtr(0);
int argc = 0;

gtk_init (ref argc, ref argv);

SynchronizationContext.SetSynchronizationContext (new
GLib.GLibSynchronizationContext ()); }

Init will fail on SetPrgname (); when mono is embedded in an application.

static void SetPrgname ()
{
GLib.Global.ProgramName = System.IO.Path.GetFileNameWithoutExtension
(Environment.GetCommandLineArgs () [0]);
}

When embedding Mono, Environment.GetCommandLineArgs () will fail because it
is not set to anything. When you run the same on mono as a standalone
application it will work because mono will pass the command line argument
via Environment.GetCommandLineArgs().

I fixed it by registering the internal call for
Environment.GetCommandLineArgs to my own fucntion and return just a dummy
string.

My suggestion would be to do the same in mono when you embed it or to
change SetPrgname  to not relay on Environment.GetCommandLineArgs ().

Best Regards
Sahin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20131102/cbd5d686/attachment.html>


More information about the Mono-devel-list mailing list