简体   繁体   English

DLL可以与其他编程语言一起使用吗?

[英]Can a DLL be used with other Programming Languages?

What programming language can support same dll? 哪种编程语言可以支持相同的dll?

I just bought a product bundled with 3 api: JAVA, .NET, C++ 我刚刚购买了与3种API捆绑在一起的产品:JAVA,.NET,C ++

In each api folder, I found dll files on .Net and C++ folder while jar file on java folder. 在每个api文件夹中,我在.Net和C ++文件夹中找到dll文件,而在java文件夹中找到jar文件。 My question is, can i integrate dll on different languages? 我的问题是,我可以在不同语言中集成dll吗? I already tried implementing a dll in java using jni and it worked. 我已经尝试过使用jni在java中实现一个dll,并且它起作用了。 I read that dll supports multi language program but why is that different dll were used with .net and c++? 我读到dll支持多语言程序,但是为什么.net和c ++使用了不同的dll?

Any answer will be appreciated. 任何答案将不胜感激。 Thanks 谢谢

It would be perfectly possible to call the C++ DLL from C# (or other .Net language), but it would be a matter of writing P/Invoke code to do so (and this is hard). 完全有可能从C#(或其他.Net语言)中调用C ++ DLL,但这将是编写P / Invoke代码来实现的(这很难)。

As a matter of convenience, the authors of the API have written a native C# wrapper for you which you can use much as you would use any other C# class. 为方便起见,API的作者为您编写了一个本机C#包装器,您可以像使用其他任何C#类一样使用它们。

(The above assumes that the "real" DLL is the C++ one - it could actually be the C# one, and the C++ DLL is a wrapper written in C++/CLI. Doesn't actually much change the logic.) (以上假设“真正的” DLL是C ++ DLL-实际上可以是C#DLL,而C ++ DLL是用C ++ / CLI编写的包装器。实际上并没有太大改变逻辑。)

Similarly writing JNI interfaces is tedious and fiddly - much better to do it once (right), rather than answer all the support calls "How do I..." 类似地,编写JNI接口既繁琐又繁琐-一次(右)做起来要好得多,而不是回答所有的支持电话“我如何...”

According to Wikipedia as of 15th of November 2016, 根据Wikipedia截至2016年11月15日的数据,

Dynamic-link library (or DLL) is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems. 动态链接库(或DLL)是Microsoft在Microsoft Windows和OS / 2操作系统中对共享库概念的实现。 These libraries usually have the file extension DLL, OCX (for libraries containing ActiveX controls), or DRV (for legacy system drivers). 这些库通常具有文件扩展名DLL,OCX(对于包含ActiveX控件的库)或DRV(对于旧式系统驱动程序)。 The file formats for DLLs are the same as for Windows EXE files – that is, Portable Executable (PE) for 32-bit and 64-bit Windows, and New Executable (NE) for 16-bit Windows. DLL的文件格式与Windows EXE文件的格式相同,即32位和64位Windows的可移植可执行文件(PE),和16位Windows的新可执行文件(NE)。 As with EXEs, DLLs can contain code, data, and resources, in any combination. 与EXE一样,DLL可以任意组合包含代码,数据和资源。

This means that you can store different things including code into a DLL. 这意味着您可以将包括代码在内的不同内容存储到DLL中。 A DLL is loaded at runtime. DLL在运行时加载。 You can load DLLs according to a language's supported features. 您可以根据语言支持的功能加载DLL。
You can do this in the following ways:- 您可以通过以下方式进行此操作:

  • In Java via the JNI interface. 在Java中,通过JNI接口。
  • In C++ C ++中
  • In any other language that supports calling DLLs. 支持调用DLL的任何其他语言。

Another point to be noted is that the DLL must be compiled for the operating system you will be calling it on before hand. 需要注意的另一点是,DLL必须针对您将要在其上调用的操作系统进行编译。 Different operating systems have different file extensions / concepts for DLLs as an analogy. 类似地,不同的操作系统对DLL具有不同的文件扩展名/概念。
For example, the following workflow is valid, 例如,以下工作流程有效,
Compile DLL in C++ -> Store in Disk -> Call your DLL from any other language like C# / C++/ Java 用C ++编译DLL- > 存储在磁盘中 -> 从其他任何语言(如C#/ C ++ / Java)调用DLL

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

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