简体   繁体   中英

how do I include dll's such as kernel32.dll which my unmanaged dll needs

I've been searching everywhere and can't find how to do this:

I'm trying to use an unmanaged dll in my c# code. using dependancy walker I found that I also need to include an import for kernel32.dll, msvcp120d.dll and msvcr120d.dll. At the moment I only call my dll like this

    [DllImport("ExApcpp.dll", CallingConvention = CallingConvention.Cdecl)]

    public extern static string cb_organise_i (int a1);

(where cb_organise_i is a function in the dll.)

I'm using xamarin and keep getting the error

[Mono] Probing '_monodroid_gref_log_delete'.
[Mono] Found as '_monodroid_gref_log_delete'.
[Mono] DllImport attempting to load: 'ExApcpp.dll'.
[Mono] DllImport error loading library './libExApcpp.dll': 'dlopen failed: library "/data/data/workex.workex/lib/./libExApcpp.dll" not found'.
[Mono] DllImport error loading library './libExApcpp.dll.so': 'dlopen failed: library "/data/data/workex.workex/lib/./libExApcpp.dll.so" not found'.
[Mono] DllImport error loading library 'libExApcpp.dll': 'dlopen failed: library "/data/data/workex.workex/lib/libExApcpp.dll" not found'.

although my dll is in the application folder. Also I don't have a file named libExApcpp.dll (I used swig and vs2013 to wrap my c++ code and make the dll)

Am I on the right lines assuming I need the other three dll's and if so how would I include/implement them?

Sorry if this is a stupid question but I've become blind to the answer.

Mono is an implementation of the CLR (Common Language Runtime). It offers the DLLs needed for managed code. Kernel32 is part of Windows, and isn't needed for managed code. It's therefore not part of Mono, nor can you provide it to Mono.

That of course means you can't run your unmanaged DLL on Mono. No surprise there; to run unmanaged code you'd need Wine instead of Mono.

You have compiled the code using Visual Studio to target desktop Windows. But your Xamarin project does not target desktop Windows, it targets Android by the look of the error messages.

In order to be able to call this unmanaged code you need to compile it using a compiler that targets the correct platform. You are not targeting desktop Windows, so don't use a desktop Windows compiler. Use a compiler that targets your actual platform.

Now, it is easy to say this, perhaps harder to achieve. Perhaps the unmanaged code is not cross-platform and relies on the Windows API. In which case you'd need to remove/replace all such non-portable dependencies.

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