DllExport Documentation

repository·master·Indexed 22 days ago

https://github.com/3f/dllexport

A tool that allows .NET assemblies (DLLs and EXEs) to export functions for use by unmanaged code such as C++, Java, Rust, or Python. It provides the [DllExport] attribute and a modified IL Assembler (ILAsm) to modify the PE format and include an Export Address Table (EAT).

Tokens
654
Snippets
1
Records
4
Agent score
28%

What's inside DllExport

  1. How DllExport works: The .export directive

    master

    DllExport works by utilizing a modified version of the IL Assembler (ILAsm). It uses a .export directive (which is part of the ILAsm compiler, not the CLR) to prepare the necessary steps for exporting symbols.

    This process involves modifying the PE (Portable Executable) format to include an Export Address Table (EAT) and generating thunk stubs so that unmanaged code can correctly transition into the managed environment.

  2. Install and set up DllExport

    master

    You can obtain and install DllExport using several methods:

    1. Direct Download (Recommended): Download the latest stable DllExport.bat directly from GitHub Releases or via the latest stable link.
    2. NuGet: You can use the DllExport NuGet package. Note that NuGet features are not guaranteed to work perfectly in all environments.
    3. GetNuTool: Use the embeddable package manager gnt to manage the installation.

    For detailed setup instructions, refer to the Quick-start Wiki.

  3. Build DllExport from source

    master

    To build the project from source, clone the repository and run the build.bat script.

    Prerequisites:

    • CMake must be installed.
    • If using the Visual Studio IDE, this relies on vsSolutionBuildEvent scripting.

    Standard Build:

    git clone https://github.com/3F/DllExport.git DllExport
    cd DllExport
    .uild Release

    Minimal Build (Assembler only):

    .uild # ilasm -x64

    Build Assembler and then the full project:

    .uild # ilasm -x64 & .uild Release

    Using GetNuTool to build:

    .tools\gnt ILAsm & .uild Release
  4. Export methods using the [DllExport] attribute

    master

    To export a method from a .NET DLL or EXE so it can be called by unmanaged code (C++, Java, Rust, Python, etc.), decorate the method with the [DllExport] attribute.

    By default, the calling convention is CallingConvention.Cdecl. You can explicitly specify other conventions like StdCall or provide a custom export name.

    Key Details:

    • Default Calling Convention: CallingConvention.Cdecl
    • Supported Modules: Both Library (.dll) and Executable (.exe) PE modules.
    [DllExport("Init", CallingConvention.Cdecl)]
    [DllExport(CallingConvention.StdCall)]
    // Cdecl is the default calling convention in .NET DllExport
    [DllExport("MyFunc")]
    [DllExport]