0

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.

edens93
  • 11
  • 2
  • 1
    Side note: invoking native code is unlikely to work at all for non-Windows platform (which seem to be your target based on Xamarin tag). Also depending on "D" (debug) versions of runtime is not a good idea... – Alexei Levenkov Jul 17 '14 at 18:22
  • kender32? Sure it's not kernel32 ? – MSalters Jul 18 '14 at 08:18
  • Why are you linking to the debug version of the runtime? Your problem is not that you aren't importing enough functions, but that your DLL is not loading. – David Heffernan Jul 18 '14 at 10:37

2 Answers2

0

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • And on Linux. And when the unmanaged DLL runs along Mono on Windows, it still doesn't run on top of Mono. – MSalters Jul 21 '14 at 06:48
  • @DavidHeffernan: No Windows tag, but there's a Xamarin tag. Trying to pinvoke kernel32 on an iPhone will not give you useful results. – MSalters Jul 21 '14 at 06:59
  • OK, I guess I assumed this was Windows because asker was trying to link to VS compiled DLLs which are clearly for windows. But this is Android right? In which case the entire premise of the question is wrong. But you can pinvoke unmanaged code from Mono. – David Heffernan Jul 21 '14 at 07:01
  • @DavidHeffernan: He's trying to use his own unmanaged DLL, which is compiled in VS2012 and therefore drags in the VS2012 runtime, as well as Kernel32. Xamarin is Android/iPhone so you can't even assume x86. – MSalters Jul 21 '14 at 07:03
0

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490