[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-list
Subject: Re: [Mono-list] Embedding mono on windows
From: "Damien DALY" <maitredede () gmail ! com>
Date: 2008-03-31 19:49:53
Message-ID: 6df580e50803311249g51f868c8g7f59afde46838531 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
[Attachment #4 (text/plain)]
I didn't made it full C# because it's to make a plugin engine for an
existing C/C++ app... Actual plugin engine is C/C++, and I would like to add
C# plugins. The C# part is easy for me, but C/C++ wrapper is hard to code
since I'm a begginer in C/C++...
If anyone can give me some samples better than those on svn, I would be
pleased :)
Thanks.
Damien
2008/3/31, Petit Eric <surfzoid@gmail.com>:
>
> Damien, to have a good luke, to forget the list in your answer.
>
>
> 2008/3/31, Damien DALY <maitredede@gmail.com>:
>
> > Hi Eric,
> >
> > What I want to do is to call my custom C function from my C#.
> >
> > I'm exposing it using C function mono_add_internal_call, like it is show
> on
> > sample at http://www.mono-project.com/Embedding_Mono
> > "Exposing C code to the CIL universe".
>
> Not sur to understand evry thing and had a very quick look at the
> link, but i don't think about mixed language in a single project type
> ?
> if you speak about the chapter :" Exposing C code to the CIL universe"
> it's wat i sayed, you need two part, one is a dll/so (a library) write
> in C managed code and a "wrapper" of it in C#.
> But if you just started the project, why don't just make evrything in C# ?
>
>
> >
> > So in my C code, I define a function with this code :
> >
> > static const void MonoMsg(MonoString *msg)
> > {
> > Error(mono_string_to_utf8(msg));
> > };
> >
> > In my C# code, I have this class :
> >
> > namespace MonoPlug
> > {
> > internal static class ClsInternal
> > {
> > [MethodImplAttribute(MethodImplOptions.InternalCall)]
> > internal extern static void MonoMsg(string message);
> > }
> > }
> >
> > I expose my C function using :
> >
> > mono_add_internal_call("MonoPlug.ClsInternal::Msg", MonoMsg);
> >
> > Under windows VS2008 it compiles and runs successfuly, but under linux,
> I
> > have compilation errors :
>
> I gues, mono compiler is more restrictive than Crosoft one, i alredy
> see it in C# in the past, there is more warning, and not sur but some
> warning are "like" error, also it's like pointer problem, right ?
> Nota : i have no C knoweldge.
>
> >
> > MonoPlug.Test.cpp:83: erreur: invalid conversion from «const void
> > (*)(MonoString*)" to «const void*"
> > MonoPlug.Test.cpp:83: erreur: initializing argument 2 of «void
> > mono_add_internal_call(const char*, const void*)"
> >
> > By focing cast to (void*) I can compile, but I have a
> MissingMethodException
> > when trying to call method...
> >
> > I know they are easy errors for C/C++ developpers, but since I'm
> starting
> > coding C/C++, I don't know if I can find mysself the answer...
> >
> > If you want, you can answer me in French...
> >
> > Thanks,
> >
> > Damien
> >
> > 2008/3/31, Petit Eric <surfzoid@gmail.com>:
> > > 2008/3/31, Damien DALY <maitredede@gmail.com>:
> > >
> > > > Thanks Robert
> > > >
> > > > I'm also sending to list (sorry for missed messages, they are
> below).
> > > >
> > > > I will try to work with these functions.
> > > >
> > > > Now, I would like to call C function from my C#, and passing
> arguments
> > to
> > > > the function (like saying hello to string argument)...
> > >
> > >
> >
> http://www.google.fr/search?q=dllimport&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:official&client=firefox-a
>
> > > an Example in this file :
> > >
> >
> http://cs-obexftp.svn.sourceforge.net/viewvc/cs-obexftp/trunk/src/obexftp/obexftpPINVOKE.cs?revision=151&view=markup
>
> > >
> > > If you are luky, try SWIG (under linux) to make the biggest work!
> > >
> > >
> > > >
> > > > Thanks,
> > > >
> > > > Damien
> > > >
> > > > 2008/3/31, Robert Jordan <robertj@gmx.net>:
> > > > > Hi,
> > > > >
> > > > > Next time please reply to the list as well.
> > > > >
> > > > > Mono_set_defaults and
> > mono_parse_default_optimizations
> > > > are not public
> > > > > anymore because they were not intended to be called from user
> code.
> > > > > The runtime is calling them for you.
> > > > >
> > > > > On (2): mono depends on GLib, GNOME's portable C library. This lib
> > > > > provides a lot of path functions:
> > > > >
> > > > >
> > > >
> >
> http://library.gnome.org/devel/glib/stable/glib-Miscellaneous-Utility-Functions.html
>
> > > > >
> > > > > See g_get_current_dir, g_build_path, etc.
> > > > >
> > > > > On Windows, mono's installer is deploying this lib automatically
> into
> > > > > mono's lib folder. Just link your app with "glib-2.0.lib".
> > > > >
> > > > >
> > > > > Robert
> > > > >
> > > > >
> > > > >
> > > > > Damien DALY wrote:
> > > > > > Yeah, it works !
> > > > > > Thanks...
> > > > > >
> > > > > > Two more questions :
> > > > > >
> > > > > > 1) I'd like to execute :
> > > > > > mono_config_parse(NULL); //To load default config
> > > > > > mono_set_defaults(0,
> > > > mono_parse_default_optimizations(NULL)); //To add
> > > > > > all optimizations
> > > > > >
> > > > > > mono_config_parse is defined in mono-config.h. I have a linker
> error
> > > > > > "unresolved symbol"
> > > > > > mono_set_defaults and
> > mono_parse_default_optimizations
> > > > are not defined...
> > > > > >
> > > > > > I'm using windows release with installer file "
> > > > > > mono-1.9-gtksharp-2.10.4-win32-4"...
> > > > > >
> > > > > > 2) How can I find the directory of current module executing in
> C++ ?
> > > > > > This is to tell mono that it must search assemblies in a sub
> folder
> > of
> > > > > > current exe... (mono_set_dirs)
> > > > > > And if you have a safe concat function for path... (like managed
> > > > > > Path.Combine)
> > > > > > And that works for any OS... :o)
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > > Damien
> > > > > >
> > > > > >
> > > > > > 2008/3/31, Robert Jordan <robertj@gmx.net>:
> > > > > > > Damien DALY wrote:
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I'd like to embed Mono into my app, but I haven't found some
> doc
> > > > > > > explaining
> > > > > > > > how to do this using Windows and VS2008 (under XP and Vista).
> > > > > > > > The starting point I have found is
> > > > > > > > http://www.mono-project.com/Embedding_Mono
> > > > > > > >
> > > > > > > > If someone has help about Ebedded Mono under Windows, I would
> be
> > > > pleased
> > > > > > > to
> > > > > > > > hear about.
> > > > > > >
> > > > > > > The docs apply to Windows/Visual Studio as well, but they don't
> > explain
> > > > > > > how to setup a project to the same extent like they do for
> linux or
> > > > > > > cygwin.
> > > > > > >
> > > > > > > Basically, you only need to generate an import library for
> > mono.dll,
> > > > > > > the dll that provides the embedding APIs.
> > > > > > >
> > > > > > > Get this file:
> > > > > > >
> > > > > > >
> > > > > > >
> > > >
> >
> http://anonsvn.mono-project.com/viewcvs/*checkout*/trunk/mono/msvc/mono.def
> > > > > > >
> > > > > > > and create mono.lib with Visual Studio's lib.exe tool:
> > > > > > >
> > > > > > > lib /nologo /def:mono.def /out:mono.lib /machine:x86
> > > > > > >
> > > > > > > Then link you application with mono.lib.
> > > > > > >
> > > > > > > Robert
> > > > > > >
> > > > > > > _______________________________________________
> > > > > > > Mono-list maillist - Mono-list@lists.ximian.com
> > > > > > > http://lists.ximian.com/mailman/listinfo/mono-list
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > Mono-list maillist - Mono-list@lists.ximian.com
> > > > http://lists.ximian.com/mailman/listinfo/mono-list
> > > >
> > > >
> > >
> >
> >
>
[Attachment #5 (text/html)]
I didn't made it full C# because it's to make a plugin engine for an existing \
C/C++ app... Actual plugin engine is C/C++, and I would like to add C# plugins. The \
C# part is easy for me, but C/C++ wrapper is hard to code since I'm a begginer in \
C/C++...<br> <br>If anyone can give me some samples better than those on svn, I would \
be pleased :)<br><br>Thanks.<br><br>Damien<br><br><div><span \
class="gmail_quote">2008/3/31, Petit Eric <<a \
href="mailto:surfzoid@gmail.com">surfzoid@gmail.com</a>>:</span><blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;"> Damien, to have a good luke, to forget the list in \
your answer.<br> <br><br> 2008/3/31, Damien DALY <<a \
href="mailto:maitredede@gmail.com">maitredede@gmail.com</a>>:<br> <br>> Hi \
Eric,<br> ><br> > What I want to do is to call my custom C function from my \
C#.<br> ><br> > I'm exposing it using C function mono_add_internal_call, \
like it is show on<br> > sample at <a \
href="http://www.mono-project.com/Embedding_Mono">http://www.mono-project.com/Embedding_Mono</a><br> \
> "Exposing C code to the CIL universe".<br> <br>Not sur to understand \
evry thing and had a very quick look at the<br> link, but i don't think about \
mixed language in a single project type<br> ?<br> if you speak about the chapter \
:" Exposing C code to the CIL universe"<br> it's wat i sayed, you need \
two part, one is a dll/so (a library) write<br> in C managed code and a \
"wrapper" of it in C#.<br> But if you just started the project, why \
don't just make evrything in C# ?<br> <br><br> ><br> > So in my C code, I \
define a function with this code :<br> ><br> > static const void \
MonoMsg(MonoString *msg)<br> > {<br> \
> \
Error(mono_string_to_utf8(msg));<br> > };<br> ><br> > In my C# code, I have \
this class :<br> ><br> > namespace MonoPlug<br> > {<br> \
> internal static class ClsInternal<br> \
> {<br> \
> \
[MethodImplAttribute(MethodImplOptions.InternalCall)]<br> \
> internal extern static void \
MonoMsg(string message);<br> > }<br> > }<br> ><br> \
> I expose my C function using :<br> ><br> > \
mono_add_internal_call("MonoPlug.ClsInternal::Msg", MonoMsg);<br> ><br> \
> Under windows VS2008 it compiles and runs successfuly, but under linux, I<br> \
> have compilation errors :<br> <br>I gues, mono compiler is more restrictive than \
Crosoft one, i alredy<br> see it in C# in the past, there is more warning, and not \
sur but some<br> warning are "like" error, also it's like pointer \
problem, right ?<br> Nota : i have no C knoweldge.<br> <br>><br> > \
MonoPlug.Test.cpp:83: erreur: invalid conversion from «const void<br> > \
(*)(MonoString*)" to «const void*"<br> \
> MonoPlug.Test.cpp:83: erreur: initializing argument 2 of \
«void<br> > mono_add_internal_call(const char*, const void*)"<br> ><br> \
> By focing cast to (void*) I can compile, but I have a MissingMethodException<br> \
> when trying to call method...<br> ><br> > I know they are easy errors for \
C/C++ developpers, but since I'm starting<br> > coding C/C++, I don't know \
if I can find mysself the answer...<br> ><br> > If you want, you can answer me \
in French...<br> ><br> > Thanks,<br> ><br> > Damien<br> ><br> > \
2008/3/31, Petit Eric <<a \
href="mailto:surfzoid@gmail.com">surfzoid@gmail.com</a>>:<br> > > 2008/3/31, \
Damien DALY <<a href="mailto:maitredede@gmail.com">maitredede@gmail.com</a>>:<br>
> ><br> > > > Thanks Robert<br> > > ><br> > > > \
I'm also sending to list (sorry for missed messages, they are below).<br> > \
> ><br> > > > I will try to work with these functions.<br> > > \
><br> > > > Now, I would like to call C function from my C#, and passing \
arguments<br> > to<br> > > > the function (like saying hello to string \
argument)...<br> > ><br> > ><br> > <a \
href="http://www.google.fr/search?q=dllimport&ie=utf-8&oe=utf-8&aq=t&r \
ls=org.mozilla:fr:official&client=firefox-a">http://www.google.fr/search?q=dllimpo \
rt&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:official&client=firefox-a</a><br>
> > an Example in this file :<br> > ><br> > <a \
href="http://cs-obexftp.svn.sourceforge.net/viewvc/cs-obexftp/trunk/src/obexftp/obexft \
pPINVOKE.cs?revision=151&view=markup">http://cs-obexftp.svn.sourceforge.net/viewvc \
/cs-obexftp/trunk/src/obexftp/obexftpPINVOKE.cs?revision=151&view=markup</a><br> \
> ><br> > > If you are luky, try SWIG (under linux) to make the biggest \
work!<br> > ><br> > ><br> > > ><br> > > > Thanks,<br> \
> > ><br> > > > Damien<br> > > ><br> > > > \
2008/3/31, Robert Jordan <<a \
href="mailto:robertj@gmx.net">robertj@gmx.net</a>>:<br> > > > > \
Hi,<br> > > > ><br> > > > > Next time please reply to the \
list as well.<br> > > > ><br> > > > > Mono_set_defaults \
and<br> > mono_parse_default_optimizations<br> > > > are not public<br> \
> > > > anymore because they were not intended to be called from user \
code.<br> > > > > The runtime is calling them for you.<br> > > \
> ><br> > > > > On (2): mono depends on GLib, GNOME's portable \
C library. This lib<br> > > > > provides a lot of path functions:<br> \
> > > ><br> > > > ><br> > > ><br> > <a \
href="http://library.gnome.org/devel/glib/stable/glib-Miscellaneous-Utility-Functions. \
html">http://library.gnome.org/devel/glib/stable/glib-Miscellaneous-Utility-Functions.html</a><br>
> > > ><br> > > > > See g_get_current_dir, g_build_path, \
etc.<br> > > > ><br> > > > > On Windows, mono's installer \
is deploying this lib automatically into<br> > > > > mono's lib \
folder. Just link your app with "glib-2.0.lib".<br> > > > \
><br> > > > ><br> > > > > Robert<br> > > > \
><br> > > > ><br> > > > ><br> > > > > Damien \
DALY wrote:<br> > > > > > Yeah, it works !<br> > > > > \
> Thanks...<br> > > > > ><br> > > > > > Two more \
questions :<br> > > > > ><br> > > > > > 1) I'd like \
to execute :<br> > > > > > \
mono_config_parse(NULL); //To load default config<br> > > > > \
> mono_set_defaults(0,<br> > > > \
mono_parse_default_optimizations(NULL)); //To add<br> > > > > > all \
optimizations<br> > > > > ><br> > > > > > \
mono_config_parse is defined in mono-config.h. I have a linker error<br> > > \
> > > "unresolved symbol"<br> > > > > > \
mono_set_defaults and<br> > mono_parse_default_optimizations<br> > > > \
are not defined...<br> > > > > ><br> > > > > > I'm \
using windows release with installer file "<br> > > > > > \
mono-1.9-gtksharp-2.10.4-win32-4"...<br> > > > > ><br> > > \
> > > 2) How can I find the directory of current module executing in C++ \
?<br> > > > > > This is to tell mono that it must search assemblies in \
a sub folder<br> > of<br> > > > > > current exe... \
(mono_set_dirs)<br> > > > > > And if you have a safe concat function \
for path... (like managed<br> > > > > > Path.Combine)<br> > > \
> > > And that works for any OS... :o)<br> > > > > ><br> \
> > > > > Thanks<br> > > > > ><br> > > > > \
> Damien<br> > > > > ><br> > > > > ><br> > > \
> > > 2008/3/31, Robert Jordan <<a \
href="mailto:robertj@gmx.net">robertj@gmx.net</a>>:<br> > > > > \
>> Damien DALY wrote:<br> > > > > >>> Hi,<br> > > \
> > >>><br> > > > > >>> I'd like to embed \
Mono into my app, but I haven't found some doc<br> > > > > >> \
explaining<br> > > > > >>> how to do this using Windows and \
VS2008 (under XP and Vista).<br> > > > > >>> The starting point \
I have found is<br> > > > > >>> <a \
href="http://www.mono-project.com/Embedding_Mono">http://www.mono-project.com/Embedding_Mono</a><br>
> > > > >>><br> > > > > >>> If someone \
has help about Ebedded Mono under Windows, I would be<br> > > > pleased<br> \
> > > > >> to<br> > > > > >>> hear about.<br> \
> > > > >><br> > > > > >> The docs apply to \
Windows/Visual Studio as well, but they don't<br> > explain<br> > > > \
> >> how to setup a project to the same extent like they do for linux or<br> \
> > > > >> cygwin.<br> > > > > >><br> > > \
> > >> Basically, you only need to generate an import library for<br> \
> mono.dll,<br> > > > > >> the dll that provides the embedding \
APIs.<br> > > > > >><br> > > > > >> Get this \
file:<br> > > > > >><br> > > > > >><br> > > \
> > >><br> > > ><br> > <a \
href="http://anonsvn.mono-project.com/viewcvs/*checkout*/trunk/mono/msvc/mono.def">http://anonsvn.mono-project.com/viewcvs/*checkout*/trunk/mono/msvc/mono.def</a><br>
> > > > >><br> > > > > >> and create mono.lib \
with Visual Studio's lib.exe tool:<br> > > > > >><br> > > \
> > >> lib /nologo \
/def:mono.def /out:mono.lib /machine:x86<br> > > > > >><br> > \
> > > >> Then link you application with mono.lib.<br> > > > \
> >><br> > > > > >> Robert<br> > > > > \
>><br> > > > > >> \
_______________________________________________<br> > > > > >> \
Mono-list maillist - <a \
href="mailto:Mono-list@lists.ximian.com">Mono-list@lists.ximian.com</a><br> > > \
> > >> <a \
href="http://lists.ximian.com/mailman/listinfo/mono-list">http://lists.ximian.com/mailman/listinfo/mono-list</a><br>
> > > > >><br> > > > > ><br> > > > \
><br> > > > ><br> > > ><br> > > ><br> > > > \
_______________________________________________<br> > > \
> Mono-list maillist - <a \
href="mailto:Mono-list@lists.ximian.com">Mono-list@lists.ximian.com</a><br> > \
> > <a \
href="http://lists.ximian.com/mailman/listinfo/mono-list">http://lists.ximian.com/mailman/listinfo/mono-list</a><br> \
> > ><br> > > ><br> > ><br> ><br> ><br> \
</blockquote></div> <br>
_______________________________________________
Mono-list maillist - Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic