[Mono-list] How to send a message from C++ (native) code to Mono on Linux (using Xlib)

Abe Gillespie abe.gillespie at gmail.com
Sun Nov 30 13:00:31 EST 2008


Chris,

I think he's looking to expose events from the C++ lib that his .Net
UI can consume, not call into the C++ lib from .Net.

-Abe

On Sun, Nov 30, 2008 at 12:43 PM, Chris Howie <cdhowie at gmail.com> wrote:
> On Sat, Nov 29, 2008 at 6:22 PM, kemo Kemic <k.kemic at yahoo.com> wrote:
>>  I am using .NET for user interface development. C++ is used for numerical
>> computation. In some cases it required to send some notifications from C++
>> to managed .NET code. On windows it is clear how to create it (and it is
>> implemented: PostMessage). Could someone, please,  help  me how to solve
>> this issue on Linux? I need the C++ part and also how  to catch the message
>> on .NET side. I am also wondering if it is  possible to make .NET code once,
>> without recompiling on Linux  (basically I will have two different C++
>> binaries and one .NET for all  platforms).
>
> The C# code can be written to compile once and run everywhere.
> (Windows-compiled binaries run on Mono, and Mono-compiled binaries run
> on MS.NET.)
>
> You will have to compile the unmanaged library for both platforms.
> You can use P/Invoke to make calls to this library, just make sure you
> declare the functions you intend to call from managed land as extern
> "C".  For example, you might do this in your library:
>
> extern "C" {
>    int some_function(const char *some_string);
> }
>
> Then in your C# library:
>
> internal class NativeCall
> {
>    [DllImport("gluelibrary")]
>    internal static extern int some_function(string some_string);
> }
>
> Just make sure that your library compiles as libgluelibrary.so on
> Linux and gluelibrary.dll on Windows.  (Of course you should probably
> call it something else, but the same basic concept applies.)
>
> Does this answer your question?
>
> --
> Chris Howie
> http://www.chrishowie.com
> http://en.wikipedia.org/wiki/User:Crazycomputers
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>


More information about the Mono-list mailing list