[Mono-list] Embedding mono on windows

Petit Eric surfzoid at gmail.com
Mon Mar 31 15:43:24 EDT 2008


2008/3/31, Petit Eric <surfzoid at gmail.com>:
> Damien, to have a good luke, to forget the list in your answer.
Oupps, i wouldlike to say "Don't forget" and not "to forget"
>
>
>  2008/3/31, Damien DALY <maitredede at 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 at gmail.com>:
>  > > 2008/3/31, Damien DALY <maitredede at 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 at 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 at 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 at lists.ximian.com
>  > > > > >> http://lists.ximian.com/mailman/listinfo/mono-list
>  > > > > >>
>  > > > > >
>  > > > >
>  > > > >
>  > > >
>  > > >
>  > > > _______________________________________________
>  > > >  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