Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think that .NET DLLs can still be loaded by native code? I could throw together a project to check if that actually works or not.

Edit: Using the tool "dllexport" (https://github.com/3F/DllExport), you can create a .NET DLL that exports a function that is callable from C/C++ code. Just LoadLibrary and GetProcAddress.



How does this differ from the Microsoft solution https://github.com/dotnet/samples/tree/main/core/nativeaot/N... ? Is it still MSIL rather than compiled, and if so where does it get the runtime from?


.NET DLL files are not only MSIL code, they are also native code. If built for the same architecture (x86, x64...) as the importing program, it can be loaded like any other DLL.

The DLL links to MSCOREE.DLL. When loaded into a process, the DLL can initialize the .NET runtime when necessary. The DLL's entry point is a jump to _CorDllMain within MSCOREE.DLL, which takes care of loading and initializing .NET if it hasn't been done before.

As for how it manages to initialize .NET from within DllMain (you're under DLL loader lock at this point), I don't know. It has to somehow get out of loader lock at some point before it loads a bunch of DLLs.


oh, neat. I recently needed to export some functions from a C# project to be used by C++ code, but at the time I researched it (June 2024), the dllexport project seemed to be frozen (last commit before that date was on 2021).

Thanks to NativeAOT, though, it seems that you can do this kind of stuff without extra dependencies which is great too!


It works quite well especially in .NET 9!

And exporting to WASM works nearly identically to DllExport.

I used that to shift all the heavy lifting to .NET 9 AOT compiled to WASM in a fun little side project I've been working on: https://evo.ryanpeden.com


Can you share more on this? Any examples that helped you or anything you've written on the WASM .NET topic?


Not yet - I just created a browser-wasm project using the .NET CLI and then experimented with it. I spent a bunch of the digging through .targets files to see what optimization options were available.

I plan to put the source on GitHub shortly so others can use it as an example. Just need to clean things up a little first.


Sounds good. It is a jungle to find the right optimization options. It's not getting that much publicity.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: