简体   繁体   English

如何包含非托管dll需要的dll(例如kernel32.dll)

[英]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. 我试图在我的C#代码中使用非托管dll。 using dependancy walker I found that I also need to include an import for kernel32.dll, msvcp120d.dll and msvcr120d.dll. 使用Dependency Walker,我发现我还需要包括kernel32.dll,msvcp120d.dll和msvcr120d.dll的导入。 At the moment I only call my dll like this 目前,我只这样调用我的dll

    [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.) (其中cb_organise_i是dll中的函数。)

I'm using xamarin and keep getting the error 我正在使用xamarin并不断收到错误消息

[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. 虽然我的dll在应用程序文件夹中。 Also I don't have a file named libExApcpp.dll (I used swig and vs2013 to wrap my c++ code and make the dll) 我也没有一个名为libExApcpp.dll的文件(我用swig和vs2013来包装我的c ++代码并制作dll)

Am I on the right lines assuming I need the other three dll's and if so how would I include/implement them? 我是否假设我需要其他三个dll,是否正确?如果需要,我将如何包含/实现它们?

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). Mono是CLR(公共语言运行时)的实现。 It offers the DLLs needed for managed code. 它提供托管代码所需的DLL。 Kernel32 is part of Windows, and isn't needed for managed code. Kernel32是Windows的一部分,托管代码不需要。 It's therefore not part of Mono, nor can you provide it to Mono. 因此,它不是Mono的一部分,也不能提供给Mono。

That of course means you can't run your unmanaged DLL on Mono. 当然,这意味着您无法在Mono上运行非托管DLL。 No surprise there; 毫不奇怪。 to run unmanaged code you'd need Wine instead of Mono. 要运行非托管代码,您将需要Wine而不是Mono。

You have compiled the code using Visual Studio to target desktop Windows. 您已经使用Visual Studio编译了代码以定位桌面Windows。 But your Xamarin project does not target desktop Windows, it targets Android by the look of the error messages. 但是您的Xamarin项目并不针对桌面Windows,而是通过错误消息的外观针对Android。

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. 您的目标不是台式机Windows,因此请勿使用台式机Windows编译器。 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. 也许非托管代码不是跨平台的,而是依赖于Windows API。 In which case you'd need to remove/replace all such non-portable dependencies. 在这种情况下,您需要删除/替换所有此类不可移植的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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