Embedded Mono: test
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Mon, 23 Jun 2014 18:44:56 +0000 (20:44 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Mon, 23 Jun 2014 18:44:56 +0000 (20:44 +0200)
Allgemeines/MonoEmbedded/MonoEmbedded.exe [new file with mode: 0755]
Allgemeines/MonoEmbedded/MonoEmbedded.sln [new file with mode: 0644]
Allgemeines/MonoEmbedded/MonoEmbedded/MonoEmbedded.csproj [new file with mode: 0644]
Allgemeines/MonoEmbedded/MonoEmbedded/Program.cs [new file with mode: 0644]
Allgemeines/MonoEmbedded/MonoEmbedded/Properties/AssemblyInfo.cs [new file with mode: 0644]
Allgemeines/MonoEmbedded/UnManagedCode/Makefile [new file with mode: 0644]
Allgemeines/MonoEmbedded/UnManagedCode/test [new file with mode: 0755]
Allgemeines/MonoEmbedded/UnManagedCode/test.c [new file with mode: 0644]

diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded.exe b/Allgemeines/MonoEmbedded/MonoEmbedded.exe
new file mode 100755 (executable)
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 (file)
index 0000000..1acdd99
--- /dev/null
@@ -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 (file)
index 0000000..6d8aeda
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{0EB75D00-2FC6-4B53-A24D-D982CAC42EA7}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>MonoEmbedded</RootNamespace>
+    <AssemblyName>MonoEmbedded</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <Externalconsole>true</Externalconsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>full</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <Externalconsole>true</Externalconsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
diff --git a/Allgemeines/MonoEmbedded/MonoEmbedded/Program.cs b/Allgemeines/MonoEmbedded/MonoEmbedded/Program.cs
new file mode 100644 (file)
index 0000000..491712b
--- /dev/null
@@ -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 (file)
index 0000000..e368a39
--- /dev/null
@@ -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 (file)
index 0000000..e69e844
--- /dev/null
@@ -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 (executable)
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 (file)
index 0000000..2c38c76
--- /dev/null
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <iostream>
+#include <mono/jit/jit.h>
+#include <mono/metadata/assembly.h>
+#include <mono/metadata/mono-config.h>
+/**
+ * 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;
+}