From: gu.martinm@gmail.com Date: Mon, 23 Jun 2014 18:44:56 +0000 (+0200) Subject: Embedded Mono: test X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=d16168120418594a557cef6087618fca88e4afe4;p=CSharpForFun%2F.git Embedded Mono: test --- diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded.exe b/Allgemeines/MonoEmbedded/MonoEmbedded.exe new file mode 100755 index 0000000..bf0b855 Binary files /dev/null and b/Allgemeines/MonoEmbedded/MonoEmbedded.exe differ diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded.sln b/Allgemeines/MonoEmbedded/MonoEmbedded.sln new file mode 100644 index 0000000..1acdd99 --- /dev/null +++ b/Allgemeines/MonoEmbedded/MonoEmbedded.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoEmbedded", "MonoEmbedded\MonoEmbedded.csproj", "{0EB75D00-2FC6-4B53-A24D-D982CAC42EA7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0EB75D00-2FC6-4B53-A24D-D982CAC42EA7}.Debug|x86.ActiveCfg = Debug|x86 + {0EB75D00-2FC6-4B53-A24D-D982CAC42EA7}.Debug|x86.Build.0 = Debug|x86 + {0EB75D00-2FC6-4B53-A24D-D982CAC42EA7}.Release|x86.ActiveCfg = Release|x86 + {0EB75D00-2FC6-4B53-A24D-D982CAC42EA7}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = MonoEmbedded\MonoEmbedded.csproj + EndGlobalSection +EndGlobal diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded/MonoEmbedded.csproj b/Allgemeines/MonoEmbedded/MonoEmbedded/MonoEmbedded.csproj new file mode 100644 index 0000000..6d8aeda --- /dev/null +++ b/Allgemeines/MonoEmbedded/MonoEmbedded/MonoEmbedded.csproj @@ -0,0 +1,42 @@ + + + + Debug + x86 + 10.0.0 + 2.0 + {0EB75D00-2FC6-4B53-A24D-D982CAC42EA7} + Exe + MonoEmbedded + MonoEmbedded + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + \ No newline at end of file diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded/Program.cs b/Allgemeines/MonoEmbedded/MonoEmbedded/Program.cs new file mode 100644 index 0000000..491712b --- /dev/null +++ b/Allgemeines/MonoEmbedded/MonoEmbedded/Program.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.CompilerServices; + +namespace MonoEmbedded +{ + class MainClass + { + public static void Main(string[] args) + { + Print("characters like \u00D6 are working? (should be an O with ¨ above it)"); + Print("More characters: ÜÖüöÇç)"); + } + + [MethodImpl(MethodImplOptions.InternalCall)] + public static extern void Print(string msg); + } +} diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded/Properties/AssemblyInfo.cs b/Allgemeines/MonoEmbedded/MonoEmbedded/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e368a39 --- /dev/null +++ b/Allgemeines/MonoEmbedded/MonoEmbedded/Properties/AssemblyInfo.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. +[assembly: AssemblyTitle ("MonoEmbedded")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("gmm003es")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. +[assembly: AssemblyVersion ("1.0.*")] +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Allgemeines/MonoEmbedded/UnManagedCode/Makefile b/Allgemeines/MonoEmbedded/UnManagedCode/Makefile new file mode 100644 index 0000000..e69e844 --- /dev/null +++ b/Allgemeines/MonoEmbedded/UnManagedCode/Makefile @@ -0,0 +1,8 @@ +all: test + +test: test.c + g++ -Wall -g -o test test.c `pkg-config --cflags --libs /usr/mymono/lib/pkgconfig/monosgen-2.pc` + +clean: + rm -f test + diff --git a/Allgemeines/MonoEmbedded/UnManagedCode/test b/Allgemeines/MonoEmbedded/UnManagedCode/test new file mode 100755 index 0000000..60bd3ea Binary files /dev/null and b/Allgemeines/MonoEmbedded/UnManagedCode/test differ diff --git a/Allgemeines/MonoEmbedded/UnManagedCode/test.c b/Allgemeines/MonoEmbedded/UnManagedCode/test.c new file mode 100644 index 0000000..2c38c76 --- /dev/null +++ b/Allgemeines/MonoEmbedded/UnManagedCode/test.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include + +/** + * Method to be used from Mono. + */ +static inline void p_Print(MonoString *str) { + std::cout << "UTF8: " << mono_string_to_utf8(str) << std::endl; + std::wcout << "UTF16: " << ((wchar_t*)mono_string_to_utf16(str)) << std::endl; +} + +/** + * This program must be run like this: ./test MonoEmbedded.exe + * (it requires one argument, even when it is not going to be used because I do not know what + * parameters to use in mono_jit_exec method, it crashes with NULL value :/) + */ +int main (int argc, char *argv[]) +{ + /* + * Load the default Mono configuration file, this is needed + * if you are planning on using the dllmaps defined on the + * system configuration + */ + mono_config_parse (NULL); + + /* + * mono_jit_init() creates a domain: each assembly is + * loaded and run in a MonoDomain. + */ + MonoDomain *domain = mono_jit_init ("../MonoEmbedded/bin/Debug/MonoEmbedded.exe"); + + /* + * Optionally, add an internal call that your startup.exe + * code can call, this will bridge startup.exe to Mono + */ + mono_add_internal_call ("MonoEmbedded.MainClass::Print", (void *)p_Print); + + /* + * Open the executable, and run the Main method declared + * in the executable + */ + MonoAssembly *assembly = mono_domain_assembly_open (domain, "../MonoEmbedded/bin/Debug/MonoEmbedded.exe"); + if (!assembly) { + exit (2); + } + + /* + * mono_jit_exec() will run the Main() method in the assembly. + * The return value needs to be looked up from + * System.Environment.ExitCode. + */ + mono_jit_exec (domain, assembly, argc - 1, argv + 1); + + return 0; +}