简体   繁体   中英

How to load c++ assemblies from c#?

I've used Assembly.Load options in c# for load c# assemblies and it was successfully worked. But using same method to load c++ assemblies, I can't get. Is there any way to load these c++ assemblies? Please share ideas. Thanks in advance.

Assembly is a term used specifically for DLLs containing .NET/CLR code. This code is generally garbage-collected and requires and interacts with the CLR.

If you need to load any other kind of DLL, the type of code in that DLL will determine how you approach it.

If the DLL can be wrapped as/converted to a COM object, it is a fairly simply matter of wrapping it, shown in this tutorial . You simply import the type library and use the generated managed wrapper instead.

If that is not feasible or desirable, use P/Invoke as shown in this tutorial . You will create import statements to specify that a function is implemented in your DLL. This will not work with C++ classes.

The third option is to actually modify the C++ to contain managed code, which requires use of C++/CLI. For most projects, that is a far larger volume of work, so I would go with one of the first two options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM