<div dir="ltr">I think that <span style="font-family:arial,sans-serif;font-size:13px">GLib.Global.ProgramName has to be set to a value.I am not sure what will happen when it is not set.</span><div><span style="font-family:arial,sans-serif;font-size:13px">In case args == null and we should set </span> <span style="font-size:13px;font-family:arial,sans-serif">GLib.Global.ProgramName to a static value like this.</span></div>
<div><font face="arial, sans-serif"><br></font></div><div><div>var args = Environment.GetCommandLineArgs ();</div><div>if (args != null && args.Length > 0){</div><div>    GLib.Global.ProgramName = System.IO.Path.GetFileNameWithoutExtension (args [0]);</div>
<div>}else</div><div>{</div><div>   GLib.Global.ProgramName = "EmbeddedMono";</div><div>}</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/11/3 "Andrés G. Aragoneses" <span dir="ltr"><<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 03/11/13 15:58, Vardar Sahin wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Environment.GetCommandLineArgs is an internal call and my assumption was<br>
that the internal call is not registered to a C function. But now I see<br>
that I can call Environment.<u></u>GetCommandLineArgs.<br>
I checked it out and Environment.GetCommandLineArgs returns null if you<br>
embed mono into your application.<br>
<br>
So you have to check for a null reference.<br>
</blockquote>
<br></div>
Ok thanks, I updated the pull request adding a null check<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
And and maybe you have to set<br>
GLib.Global.ProgramName to static name in case.<br>
</blockquote>
<br></div>
What do you mean? GLib.Global.ProgramName is already static.<br>
<br>
Thanks<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<br>
<br>
2013/11/2 "Andrés G. Aragoneses" <<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a><br>
<mailto:<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a>>><br>
<br>
<br></div><div class="im">
    Being not registered means that accessing GetCommandLineArgs throws<br>
    an exception? If yes, what kind?<br>
<br>
<br>
    On 02/11/13 22:10, Vardar Sahin wrote:<br>
<br>
        Hey Andrés,<br>
<br>
        thanks for the quick replay. I am not sure if this will fix the<br>
        problem.<br>
        I think the problem is that you can not call<br></div>
        Environment.__<u></u>GetCommandLineArgs() when you embed mono.<br>
        Environment.__<u></u>GetCommandLineArgs() is an internal call and it<div class="im"><br>
        seems like<br>
        it is not registered when you embed mono.<br>
<br>
        Best<br>
        Sahin<br>
<br>
<br>
<br>
<br>
        2013/11/2 "Andrés G. Aragoneses" <<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a><br>
        <mailto:<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a>><br></div>
        <mailto:<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a> <mailto:<a href="mailto:knocte@gmail.com" target="_blank">knocte@gmail.com</a>>>><div class="im"><br>
<br>
<br>
             On 02/11/13 21:42, Vardar Sahin wrote:<br>
<br>
                 Hey monodev fellows,<br>
<br>
                 first of all I appreciate all your hard work and want to<br>
                 contribute this<br>
                 to the mono project.<br>
<br>
                 Right now it is not possible to use GTK# with an<br>
        application which<br>
                 embeds mono. GTK# works just fine if you use mono as a<br>
        standalone<br>
                 application eg mono.exe.<br>
<br>
                 The reason why GTK# does not works when you embed mono<br>
        is as<br>
                 fallowing.<br>
<br>
                 Each GTK# Application has to call Application.Init().<br>
<br>
                 This functions is like this.<br>
<br>
                 public static void Init ()<br>
                 {<br>
                 SetPrgname ();<br>
                 IntPtr argv = new IntPtr(0);<br>
                 int argc = 0;<br>
<br>
                 gtk_init (ref argc, ref argv);<br>
<br></div>
                 SynchronizationContext.____<u></u>SetSynchronizationContext (new<br>
                 GLib.____<u></u>GLibSynchronizationContext ());}<div class="im"><br>
<br>
<br>
                 Init will fail on SetPrgname (); when mono is embedded<br>
        in an<br>
                 application.<br>
<br>
                 static void SetPrgname ()<br>
                 {<br>
                 GLib.Global.ProgramName =<br></div>
                 System.IO.Path.____<u></u>GetFileNameWithoutExtension<br>
                 (Environment.____<u></u>GetCommandLineArgs () [0]);<div class="im"><br>
<br>
                 }<br>
<br>
                 When embedding Mono, Environment.GetCommandLineArgs ()<br>
        will fail<br>
                 because<br>
                 it is not set to anything. When you run the same on<br>
        mono as a<br>
                 standalone<br>
                 application it will work because mono will pass the<br>
        command line<br></div>
                 argument via Environment.____<u></u>GetCommandLineArgs().<div class="im"><br>
<br>
<br>
                 I fixed it by registering the internal call for<br>
                 Environment.GetCommandLineArgs to my own fucntion and<br>
        return just a<br>
                 dummy string.<br>
<br>
                 My suggestion would be to do the same in mono when you<br>
        embed it<br>
                 or to<br>
                 change SetPrgname  to not relay on<br>
                 Environment.GetCommandLineArgs ().<br>
<br>
<br>
             Sahin, wouldn't this also fix your use case?<br>
<br></div>
        <a href="https://github.com/mono/gtk-____sharp/pull/90/files" target="_blank">https://github.com/mono/gtk-__<u></u>__sharp/pull/90/files</a><br>
        <<a href="https://github.com/mono/gtk-__sharp/pull/90/files" target="_blank">https://github.com/mono/gtk-_<u></u>_sharp/pull/90/files</a>><div class="im"><br>
             <<a href="https://github.com/mono/gtk-__sharp/pull/90/files" target="_blank">https://github.com/mono/gtk-_<u></u>_sharp/pull/90/files</a><br>
        <<a href="https://github.com/mono/gtk-sharp/pull/90/files" target="_blank">https://github.com/mono/gtk-<u></u>sharp/pull/90/files</a>>><br>
<br>
<br>
             Thanks<br>
<br>
<br></div>
             ______________________________<u></u>_____________________<br>
             Mono-devel-list mailing list<br>
             Mono-devel-list@lists.ximian._<u></u>___com<br>
             <mailto:<a href="mailto:Mono-devel-list@lists." target="_blank">Mono-devel-list@lists.</a><u></u>__<a href="http://ximian.com" target="_blank">ximian.com</a><br>
        <mailto:<a href="mailto:Mono-devel-list@lists.ximian.com" target="_blank">Mono-devel-list@lists.<u></u>ximian.com</a>>><br>
        <a href="http://lists.ximian.com/____mailman/listinfo/mono-devel-____list" target="_blank">http://lists.ximian.com/____<u></u>mailman/listinfo/mono-devel-__<u></u>__list</a><br>
        <<a href="http://lists.ximian.com/__mailman/listinfo/mono-devel-__list" target="_blank">http://lists.ximian.com/__<u></u>mailman/listinfo/mono-devel-__<u></u>list</a>><br>
<br>
        <<a href="http://lists.ximian.com/__mailman/listinfo/mono-devel-__list" target="_blank">http://lists.ximian.com/__<u></u>mailman/listinfo/mono-devel-__<u></u>list</a><br>
        <<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/<u></u>mailman/listinfo/mono-devel-<u></u>list</a>>><div class="im"><br>
<br>
<br>
<br>
<br>
<br>
        ______________________________<u></u>___________________<br>
        Mono-devel-list mailing list<br>
        Mono-devel-list@lists.ximian._<u></u>_com<br>
        <mailto:<a href="mailto:Mono-devel-list@lists.ximian.com" target="_blank">Mono-devel-list@lists.<u></u>ximian.com</a>><br>
        <a href="http://lists.ximian.com/__mailman/listinfo/mono-devel-__list" target="_blank">http://lists.ximian.com/__<u></u>mailman/listinfo/mono-devel-__<u></u>list</a><br>
        <<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/<u></u>mailman/listinfo/mono-devel-<u></u>list</a>><br>
<br>
<br>
<br>
    ______________________________<u></u>___________________<br>
    Mono-devel-list mailing list<br>
    Mono-devel-list@lists.ximian._<u></u>_com<br>
    <mailto:<a href="mailto:Mono-devel-list@lists.ximian.com" target="_blank">Mono-devel-list@lists.<u></u>ximian.com</a>><br>
    <a href="http://lists.ximian.com/__mailman/listinfo/mono-devel-__list" target="_blank">http://lists.ximian.com/__<u></u>mailman/listinfo/mono-devel-__<u></u>list</a><br>
    <<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/<u></u>mailman/listinfo/mono-devel-<u></u>list</a>><br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com" target="_blank">Mono-devel-list@lists.ximian.<u></u>com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/<u></u>mailman/listinfo/mono-devel-<u></u>list</a><br>
<br>
</div></blockquote><div class=""><div class="h5">
<br>
<br>
______________________________<u></u>_________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com" target="_blank">Mono-devel-list@lists.ximian.<u></u>com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/<u></u>mailman/listinfo/mono-devel-<u></u>list</a><br>
</div></div></blockquote></div><br></div></div></div>