在本机c ++中使用.net编译的dll

时间:2022-03-18 05:06:07

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.

据我所知,任何.NET程序都被编译为MSIL,它被送到CLR,它将它编译成汇编代码,并在JIT的帮助下执行它。

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++.

我想知道,因为.NET是win32 api的包装器,CLR最终将MSIL转换为汇编程序。我是不是可以在C#中编写一些功能,制作一个dll然后我使用一个工具,使它成为一个完整的.net独立文件,供我在非托管代码中使用,如C或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.

我在谈论Interops和COM吗?这个想法不同于它吗?我的目标是在没有.NET框架的机器上运行.NET dll。

5 个解决方案

#1


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.

您可以使用本机映像生成器(Ngen.exe)将MSIL DLL编译为本机代码DLL,但这不允许您在没有.NET Framework的系统上运行它。您仍然会引用框架的其他DLL,即使您包含这些DLL,它也不适用于没有.NET框架的系统,因为该框架不仅仅是DLL的集合。

#2


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

这篇KB文章解释了一种从本机代码调用托管方法的方法。但是,您仍然需要.NET框架。

#3


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

该项目将允许您进行非托管导出.NET的静态方法。

#4


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.

它不是受支持的方式,许多功能(如Reflection)依赖于比原始机器代码更高级别提供的元数据。有些程序(称为.NET链接器)可能有所帮助,但它们并非100%可靠。

#5


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....

如果你在网上浏览,我认为有许多工具可以“编译”.NET程序集/代码以消除他们对框架的需求。不确定他们的工作情况如何......

#1


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.

您可以使用本机映像生成器(Ngen.exe)将MSIL DLL编译为本机代码DLL,但这不允许您在没有.NET Framework的系统上运行它。您仍然会引用框架的其他DLL,即使您包含这些DLL,它也不适用于没有.NET框架的系统,因为该框架不仅仅是DLL的集合。

#2


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

这篇KB文章解释了一种从本机代码调用托管方法的方法。但是,您仍然需要.NET框架。

#3


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

该项目将允许您进行非托管导出.NET的静态方法。

#4


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.

它不是受支持的方式,许多功能(如Reflection)依赖于比原始机器代码更高级别提供的元数据。有些程序(称为.NET链接器)可能有所帮助,但它们并非100%可靠。

#5


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....

如果你在网上浏览,我认为有许多工具可以“编译”.NET程序集/代码以消除他们对框架的需求。不确定他们的工作情况如何......