简体   繁体   中英

Resolve an C++ assembly in C#

I have an C# WPF project, I need to add some c++ dll in that to use functions implemented inside it. If I straight use

MyClassinDll myc = new MyClassinDll();

I get multiple not resolve file not found exception, writer of dll advice me to use

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly);

to load C++ dll as that c++ dll has other c++ dll as dependency.

Is it possible to use C++ dll class, function without reflection?

And use it like mvc.MyMethod(a,b,c) directly, as reflection takes time and complicating reference?

I would assume that MyClassinDll is defined in a managed dll that you have a static reference to. If this file does not load a likely explanation is that it depend on other, unmanaged dll-files that cannot be loaded. Reflection does not solve this issue since the code still must be loaded somehow.

If you want to load a unmanaged dll you would typically use dllImport

edit: Unmanaged dlls are loaded by the linker according to the search order . The first location is typically "The directory from which the application loaded." The problem is usually to find out what dlls are missing

A possible candidate is VS c++ runtime , this should be packaged with the library you are using. Finding missing dlls is a bit more complicated for native dependencies. The classical tool is dependency walker , but there are others. It is also possible to use process monitor to find failed resolutions . Or ask the vendor of the library to provide correct installation and usage instructions for the library. Knowing exactly what dlls is missing would help when contacting the vendor, but should not be required. If needed, ask for a minimal application that uses the library to demonstrate that it works.

Please note that when taking about assemblies and dlls there are only "native" and "managed" distinctions that are relevant. C++ might be used to write a managed assembly, or a native one. So it helps to be specific.

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