{"id":13390136,"url":"https://github.com/3F/DllExport","last_synced_at":"2025-03-13T15:31:51.287Z","repository":{"id":41403608,"uuid":"61877768","full_name":"3F/DllExport","owner":"3F","description":".NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)","archived":false,"fork":false,"pushed_at":"2024-07-18T23:23:30.000Z","size":2365,"stargazers_count":961,"open_issues_count":36,"forks_count":133,"subscribers_count":56,"default_branch":"master","last_synced_at":"2024-10-15T01:07:54.461Z","etag":null,"topics":["conari","coreclr","coreclr-ilasm","dllexport","dotnet-dllexport","exported-functions","getnutool","hmsbuild","ilasm","ildasm","mvssln","pe32","pe32-plus","pinvoke","tools"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3F.png","metadata":{"files":{"readme":"Readme.md","changelog":"changelog.txt","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["3F.github.io/fund"]}},"created_at":"2016-06-24T10:42:26.000Z","updated_at":"2024-10-02T03:53:43.000Z","dependencies_parsed_at":"2024-06-09T23:31:26.772Z","dependency_job_id":"d4136349-6ba9-44fd-946e-7f8b371de55e","html_url":"https://github.com/3F/DllExport","commit_stats":{"total_commits":214,"total_committers":6,"mean_commits":"35.666666666666664","dds":"0.33644859813084116","last_synced_commit":"c1cc52fa13f563f97a2b4fe08bfb541c69195866"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3F%2FDllExport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3F%2FDllExport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3F%2FDllExport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3F%2FDllExport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3F","download_url":"https://codeload.github.com/3F/DllExport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221197541,"owners_count":16774537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conari","coreclr","coreclr-ilasm","dllexport","dotnet-dllexport","exported-functions","getnutool","hmsbuild","ilasm","ildasm","mvssln","pe32","pe32-plus","pinvoke","tools"],"created_at":"2024-07-30T14:00:36.324Z","updated_at":"2025-03-13T15:31:51.273Z","avatar_url":"https://github.com/3F.png","language":"C#","funding_links":["3F.github.io/fund"],"categories":["C# #","C#","C# (212)"],"sub_categories":[],"readme":"# [.NET DllExport](https://github.com/3F/DllExport)\n\n*.NET DllExport* with .NET Core support (aka ***3F**/DllExport* aka *DllExport.**bat***)\n\n[![Build status](https://ci.appveyor.com/api/projects/status/hh2oxibqoi6wrdnc/branch/master?svg=true)](https://ci.appveyor.com/project/3Fs/dllexport-ix27o/branch/master)\n[![Release](https://img.shields.io/github/release/3F/DllExport.svg)](https://github.com/3F/DllExport/releases/latest)\n[![License](https://img.shields.io/badge/License-MIT-74A5C2.svg)](https://github.com/3F/DllExport/blob/master/LICENSE.txt)\n\n[`DllExport`](https://3F.github.io/DllExport/releases/latest/manager/)`-help`\n\n```csharp\n[DllExport(\"Init\", CallingConvention.Cdecl)]\n[DllExport(CallingConvention.StdCall)]\n// Cdecl is the default calling convention in .NET DllExport\n[DllExport(\"MyFunc\")]\n[DllExport]\n```\n\nBased on *UnmanagedExports* that was created by Robert Giesecke. His [page](https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports).\n\n***.NET DllExport*** is a [different project](https://github.com/3F/DllExport/issues/87#issuecomment-438576100) that was developed by Denis Kuzmin [ 「 ☕ 」 ](https://3F.github.io/fund)\n\n```\nCopyright (c) 2009-2015  Robert Giesecke\nCopyright (c) 2016-2025  Denis Kuzmin \u003cx-3F@outlook.com\u003e github/3F\n```\n\n\u003e [ ***[Quick start](https://github.com/3F/DllExport/wiki/Quick-start)*** ] [ [Examples: C++, C#, Java, ...](https://github.com/3F/DllExport/wiki/Examples) ] \n\u003e -\u003e { **[Wiki](https://github.com/3F/DllExport/wiki)** } { [🧪 Demo src](https://github.com/3F/Examples/tree/master/DllExport/BasicExport) }\n\n[![](https://github.com/3F/DllExport/blob/master/Resources/img/DllExport.png?raw=true)](https://3F.github.io/DllExport/releases/latest/manager/)\n[![](https://github.com/3F/DllExport/blob/36d452268c1f69b5c8dd5e22cc106c71ac76a82c/Resources/img/screencast_Complex_types.jpg?raw=true)](https://www.youtube.com/watch?v=QXMj9-8XJnY)\n\nFor Lua, consider using [LuNari](https://github.com/3F/LuNari)\n\n```csharp\n[DllExport]\npublic static int entrypoint(IntPtr L)\n{\n    using Lua\u003cILua53\u003e lua = new(\"Lua.dll\");\n    ...\n    lua.pushcclosure(L, onProc, 0);\n    lua.setglobal(L, \"onKeyDown\");\n    LuaNumber num = lua.tonumber\u003cLuaNumber\u003e(L, 7);\n    ...\n}\n```\n\nFor working with **unmanaged** memory including native or binary data from the heap and binding between .NET and unmanaged native C/C++ etc, try [Conari](https://github.com/3F/Conari) (Wiki. [**Quick-start**](https://github.com/3F/Conari/wiki/Quick-start))\n\n[`[⏯]`](https://github.com/3F/DllExport/blob/master/src/DllExport/assets/NetfxAsset/Basic.cs)\n\n```csharp\n[DllExport] // DllExportModifiedClassLibrary.dll\npublic static IntPtr callme(TCharPtr str, IntPtr structure)\n{\n    if(str != \"Hello world!\") return IntPtr.Zero;\n\n    structure.Native().f\u003cint\u003e(\"x\", \"y\").build(out dynamic v);\n    if(v.x \u003e v.y)\n    {\n        structure.Access().write\u003cint\u003e(8);\n    }\n    return new NativeArray\u003cint\u003e(-1, v.x, 1, v.y);\n}\n```\n\n[`[⏯]`](https://github.com/3F/DllExport/blob/master/src/DllExport/UnitedTest/NetfxAssetBasicTest.cs)\n\n```csharp\n... // host side via C/C++, Java, Rust, Python, ... or even same dotnet C#\nusing NativeString\u003cTCharPtr\u003e ns = new(\"Hello world!\");\nusing NativeStruct\u003cArg\u003e nstruct = new(new Arg() { x = 7, y = 5 });\n\nusing dynamic l = new ConariX(\"DllExportModifiedClassLibrary.dll\");\nIntPtr ptr = l.callme\u003cIntPtr\u003e(ns, nstruct);\n\nusing NativeArray\u003cint\u003e nr = new(4, ptr); // (nstruct.Data.x == 8) != (nr[1] == 7)\n```\n\n*.NET DllExport* supports both Library (**.dll**) and Executable (**.exe**) PE modules.\n\n`[⏯]` See also demo project here: https://github.com/3F/Examples/tree/master/DllExport/BasicExport\n\n## How does it work\n\nCurrent features has been implemented through [ILDasm](https://github.com/3F/coreclr/tree/master/src/ildasm) \u0026 [ILAsm](https://github.com/3F/coreclr/tree/master/src/ilasm) that prepares all the necessary steps via `.export` directive ([it's part of the ILAsm compiler, **not** CLR](https://github.com/3F/DllExport/issues/45#issuecomment-317802099)).\n\n**What inside ? how does work the .export directive ?**\n\nRead about format PE32/PE32+, start with grammar from asmparse and move to writer:\n\n```cpp\n...\n//yacc\nif(PASM-\u003em_pCurMethod-\u003em_dwExportOrdinal == 0xFFFFFFFF)\n{\n  PASM-\u003em_pCurMethod-\u003em_dwExportOrdinal = $3;\n  PASM-\u003em_pCurMethod-\u003em_szExportAlias = $6;\n  if(PASM-\u003em_pCurMethod-\u003em_wVTEntry == 0) PASM-\u003em_pCurMethod-\u003em_wVTEntry = 1;\n  if(PASM-\u003em_pCurMethod-\u003em_wVTSlot  == 0) PASM-\u003em_pCurMethod-\u003em_wVTSlot = $3 + 0x8000;\n}\n...\nEATEntry*   pEATE = new EATEntry;\npEATE-\u003edwOrdinal = pMD-\u003em_dwExportOrdinal;\npEATE-\u003eszAlias = pMD-\u003em_szExportAlias ? pMD-\u003em_szExportAlias : pMD-\u003em_szName;\npEATE-\u003edwStubRVA = EmitExportStub(pGlobalLabel-\u003em_GlobalOffset+dwDelta);\nm_EATList.PUSH(pEATE);\n...\n// logic of definition of records into EXPORT_DIRECTORY (see details from PE format)\nHRESULT Assembler::CreateExportDirectory()  \n{\n...\n    IMAGE_EXPORT_DIRECTORY  exportDirIDD;\n    DWORD                   exportDirDataSize;\n    BYTE                   *exportDirData;\n    EATEntry               *pEATE;\n    unsigned                i, L, ordBase = 0xFFFFFFFF, Ldllname;\n    ...\n    ~ now we're ready to miracles ~ vtfxup thunk stubs and ~...\n```\n\nRead also my brief explanations here: [AssemblyRef encoding](https://github.com/3F/DllExport/issues/125#issuecomment-561245575) / [about mscoree](https://github.com/3F/DllExport/issues/45#issuecomment-317802099) / [DllMain \u0026 the export-table](https://github.com/3F/DllExport/issues/5#issuecomment-240697109) / [DllExport.dll](https://github.com/3F/DllExport/issues/28#issuecomment-281957212) / [ordinals](https://github.com/3F/DllExport/issues/8#issuecomment-245228065) ...\n\n## How to get DllExport\n\nUse directly latest stable [DllExport.bat](https://3F.github.io/DllExport/releases/latest/manager/) (~28 KB). Read [Wiki](https://github.com/3F/DllExport/wiki/Quick-start)\n\nNote: NuGet features are not guaranteed [[?](https://github.com/3F/DllExport/wiki/DllExport-Manager-Q-A)] (tl;dr something may not work or not work properly)\n\n* Get it from [GitHub Releases](https://github.com/3F/DllExport/releases/latest). Or link to latest stable: https://3F.github.io/DllExport/releases/latest/manager/\n* Or from [![NuGet package](https://img.shields.io/nuget/v/DllExport.svg)](https://www.nuget.org/packages/DllExport/) Visual Studio Package Manager can still distribute and activate *DllExport.bat* for solution folder in most default setup cases.\n* Or use [embeddable package manager *GetNuTool*](https://github.com/3F/GetNuTool)\n\nRead [ **[Documentation](https://github.com/3F/DllExport/wiki/DllExport-Manager)** ]\n\n## Build .NET DllExport from source\n\n```bat\ngit clone https://github.com/3F/DllExport.git DllExport\ncd DllExport\n```\n\nCall *build.bat* to build final binaries like `DllExport.\u003cversion\u003e.nupkg`, Manager, tests, zip-archives, and related:\n\n```batch\n.\\build Release\n```\n\nNote, this relies on [vsSolutionBuildEvent](https://github.com/3F/vsSolutionBuildEvent) scripting **if** you're using Visual Studio **IDE**.\n\n### Modified IL Assembler\n\nWe're using **[3F's](https://github.com/3F) modified versions** specially for *.NET DllExport* project\n* https://github.com/3F/coreclr\n\nThis helps to avoid some problems [like this](https://github.com/3F/DllExport/issues/125#issuecomment-561245575), or [this](https://github.com/3F/DllExport/issues/17), and more ...\n\nTo build minimal version:\n\n```batch\n.\\build # ilasm -x64\n```\n\nMake sure you have installed [CMake](https://cmake.org/download/) before build.\n\nTo build assembler and use exactly this compiled version with *DllExport*, command like:\n\n```batch\n.\\build # ilasm -x64 \u0026 .\\build Release\n```\n\nAlternatively you can get official compiled versions via [![NuGet](https://img.shields.io/nuget/v/ILAsm.svg)](https://www.nuget.org/packages/ILAsm/)\n\nOr like:\n\n```batch\n:: ILAsm/9.3.0\n.tools\\gnt ILAsm \u0026 .\\build Release\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3F%2FDllExport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3F%2FDllExport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3F%2FDllExport/lists"}