[Mono-bugs] [Bug 432408] New: [WIN32] Can't p/invoke dlls which link into cygwin*.dll

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Oct 5 12:55:21 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=432408


           Summary: [WIN32] Can't p/invoke dlls which link into cygwin*.dll
           Product: Mono: Runtime
           Version: SVN
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: misc
        AssignedTo: lupus at novell.com
        ReportedBy: robertj at gmx.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


I always wondered why I can't use Mono's WinForms on my systems at all. It was
simply hanging during the last *years* until I started to debug the problem.

It turned out that the following method is hanging:

System.Drawing.Graphics.FromHwnd (IntPtr)

A small test case revealed that, if fact, the *compilation* of
Graphics.FromHwnd was never terminating:

using System;
using System.Drawing;

class Program
{
        static void Main ()
        {
                Graphics.FromHwnd (IntPtr.Zero);
        }
}

mono -v -v -v test.exe is hanging after it outputs:

class System.Drawing.GDIPlus needs init call for UseX11Drawable
class System.Drawing.GDIPlus needs init call for Display

So I had a closer look at System.Drawing.Graphics.FromHwnd's OS switch code:

See
http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs?content-type=text%2Fplain&view=co

When I comment out the whole "if (GDIPlus.UseX11Drawable)" conditional,
WinForms starts working as expected. Uh huh. So it seems to be related to the
X11 p/invoke. But I'm on Windows, so they should not matter, no?

It turned out I actually have libX11.dll on my systems, as a part of cygwin's
X11 server!

A quick test revealed that no decent non-cygwin app is able to LoadLibrary a
cygwin-dependent dll:

---

/*
 * compile with: "gcc -o cygshared.dll cygshared.c -shared"
 */

int test ()
{
        return 42;
}

---

/*
 * compile with: "cl usecyglib.c"
 */

#include <windows.h>

int main (void)
{
        LoadLibrary ("cygshared.dll");
        printf ("done\n");
}

---
using System;
using System.Runtime.InteropServices;

class Program
{
        [DllImport("cygshared.dll")]
        static extern int test ();

        static void Main ()
        {
                Console.WriteLine (42 == test ());
        }
}


IIRC, cygwin.dll is messing with SEH exception handling which breaks a lot of
apps including Mono and MS.NET.


A quick fix for the issue could be as simple as this:

Index: data/config.in
===================================================================
--- data/config.in      (revision 113696)
+++ data/config.in      (working copy)
@@ -15,7 +15,7 @@
        <dllmap dll="i:msvcrt.dll" target="@LIBC@" os="!windows"/>
        <dllmap dll="sqlite" target="@SQLITE@" os="!windows"/>
        <dllmap dll="sqlite3" target="@SQLITE3@" os="!windows"/>
-       <dllmap dll="libX11" target="@X11@" os="!windows" />
+       <dllmap dll="libX11" target="@X11@"/>
        <dllmap dll="libcairo-2.dll" target="libcairo.so.2" os="!windows"/>


We simply map libX11.dll to the on Windows non existing libX11.so as well.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list