Giter Club home page Giter Club logo

dhost's Introduction

DHost

Warning

Currently, Only .NET 5.0 or higher is supported.

A simple .NET native-host wrapper for C++

How to build

Summary

$ mkdir build
$ cd build
$ cmake -DNETHOST_RUNTIME_IDENTIFIER="linux-x64" -DNETHOST_RUNTIME_VERSION="8.0.3" ../
$ make # use what you configured with cmake

CMake Variables

Warning

Target platform not altered even if mismatched with NETHOST_RUNTIME_IDENTIFIER. To change target platform, Use cross-platform tools such as MINGW.

  • NETHOST_RUNTIME_IDENTIFIER : .NET RID (See Catalog)
  • NETHOST_RUNTIME_VERSION : .NET Runtime Version (See Version List)

How to use (Sample)

  • clr.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>
  • Program.cs
internal static class Program
{
	public static void Entry()
	{
		Console.WriteLine($"Hello from '{typeof(Program).AssemblyQualifiedName}'");
	}

	public static void Main()
	{
		// dummy
	}
}
  • main.cpp

Important

When specifying type, Assembly qualified name is required.

#include "library.h"

int main()
{
    DHost ctx("clr.runtimeconfig.json");

    if (!ctx.LoadAssembly("clr.dll"))
    {
        puts("asm");
        return -1;
    }

    const auto main = reinterpret_cast<void(*)()>(ctx.LoadMethod(
        "Program, clr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
        "Entry",
        "System.Action, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"));
    if (!main)
    {
        puts("fptr");
        return -1;
    }

    main();

    return 0;
}

dhost's People

Contributors

sharp0802 avatar

Stargazers

DevZeta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.