[Mono-devel-list] GTK# application on Windows (ms.net problem)

Jonathan Pryor jonpryor at vt.edu
Mon Nov 22 09:04:29 EST 2004

On Mon, 2004-11-22 at 00:14 +0100, Alain Favre wrote:
> The example below works perfectly with the mono runtime on windows or
> on Linux suse 9.1 but not with the MS.net runtime
> I want In my Gtk# application to use some unicode character like this one 'â'
> I tried both of this :
> Gtk.Window.Title = "Tâches"
> Gtk.Window.Title = "t\u00E2ches" 
> I compile and lauch with the mono runtime. I got no problem everythink
> runs well.
> But with the Ms.Net (1.1) runtime nothink is written in the Window.Title
> I tried to compile with :
>  - ms.net release mode
> -mcs (1.1.2) with -codebase:utf8 or without 
> And It doesnt' work.

This is a Gtk# bug/Mono feature.

Mono's string marshaler doesn't support "Ansi"; instead, Ansi is an
alias for UTF-8.  So
System.Runtime.InteropServices.Marshal.PtrToStringAnsi generates a UTF-8
encoded string on Mono.

.NET generates a locale-specific encoded string such as latin1 or SJIS.

The Gtk# "bug" is that it relies on the aliasing of "Ansi" and UTF-8.
All of the Gtk# P/Invoke calls specify CharSet.Ansi (as this is the
default for DllImport), while GTK+ requires that all strings be encoded
in UTF-8.  Consequently, Gtk# behaves properly on Mono, but doesn't work
for all languages on .NET.

IIRC, Gtk# plans on fixing this solution in the future (either by using
custom marshaling, or changing the marshaler code), but I don't know
when this will be completed.

 - Jon

More information about the Mono-devel-list mailing list