Skip to content

Instantly share code, notes, and snippets.

@tqk2811
Forked from zwcloud/MonoScriptTry.cpp
Created February 16, 2025 19:34
Show Gist options
  • Save tqk2811/be176358c9d227c173137be155d79bff to your computer and use it in GitHub Desktop.
Save tqk2811/be176358c9d227c173137be155d79bff to your computer and use it in GitHub Desktop.
Trying mono in C++
using System;
public class HelloWorld
{
static public void Main()
{
Console.WriteLine("Hello Mono World");
}
}
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#pragma comment(lib, "mono-2.0.lib")
int main(int argc, char* argv[])
{
mono_set_dirs("C:\\Program Files (x86)\\Mono\\lib",
"C:\\Program Files (x86)\\Mono\\etc");
MonoDomain *domain;
domain = mono_jit_init("HelloWorld");
MonoAssembly *assembly;
char* assemblyPath = "D:\\Mono\\hello.exe";
assembly = mono_domain_assembly_open(domain, assemblyPath);
if (!assembly)
return 1;
int returnValue = mono_jit_exec(domain, assembly, argc, argv);
mono_jit_cleanup(domain);//crash here
return returnValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment