Using a .net compiled dll inside native c++

2019-02-16 01:28发布

as i understand that any .NET program gets compiled to MSIL which is fed to the CLR which compiles it to the assembly code and along with the help of JIT it executes it.

I was wondering, as .NET is a wrapper around the win32 api and the CLR ultimately converts the MSIL to assembly program. Isn't it possible for me to write some functionality in C#, make to a dll and then i use a tool which makes it a complete .net independent file for me to use inside unmanaged code like in C or C++.

Am i talking about Interops and COM? Isn't this idea different from it? My aim is to run a .NET dll on machine not having .NET framework.

5条回答
放荡不羁爱自由
2楼-- · 2019-02-16 01:50

This project will allow you to make unmanaged exports .NET of static methods.

查看更多
3楼-- · 2019-02-16 02:02

You can use the Native Image Generator (Ngen.exe) to compile a MSIL DLL to a native code DLL, but this will not allow you to run it on a system without the .NET Framework. You will still have references to other DLLs of the framework and even if you include these DLLs, it will not work on a system without the .NET framework, because the framework is more than just a collection of DLLs.

查看更多
看我几分像从前
4楼-- · 2019-02-16 02:02

It's not a supported way and many features (like Reflection) rely on metadata provided at a higher level than raw machine code. There are some programs (called .NET linkers) that might help, but they are not 100% reliable.

查看更多
别忘想泡老子
5楼-- · 2019-02-16 02:06

This KB article explains a way to call managed methods from native code. However, you still need to have the .NET framework.

查看更多
迷人小祖宗
6楼-- · 2019-02-16 02:09

If you poke around on the web, I think there are a number of tools to 'compile' .NET assemblies/code to remove their need of the framework. Not sure how well they work....

查看更多
登录 后发表回答