创建 DLL 的编程语言:C++或 C#
这不是编程疑问!
我将为某些应用程序编写一个 DLL。 我有两个选项可供选择: C++ 或 C# 我应该用哪种语言编写 DLL?
这会影响功能吗?
我是一个完全的新手,不了解 C++ 和 C#(但不了解 C# 中的一些小程序)。
用 C++ 或 C# 编写 DLL 的优点和缺点是什么?
非常感谢您抽出时间!
问候, 斯瓦南德!
This is NOT a Programming doubt!
I am going to write a DLL for some application.
I have two options to choose from: C++ or C# In which language I should write DLL?
Does that affects functionality?
I am a completely newbie and Unaware of both C++ and C# (but Some Small programs in C#).
What are Pros and Cons about Writting DLL in C++ or C#?
Thank You very much for your time!
Regards,
Swanand!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
DLL 最好用 C 编写:)
让我解释一下:
DLL 是在 C++ 进入主流使用之前构思的。它们是为 C 语言创建的。您可以使用 C++ 编写 DLL,但只能在使用与 DLL 相同版本的同一编译器编写的应用程序中轻松使用它们。与 C++ 不同,AC DLL 可以在 .NET 中使用(是的,我知道,从技术上讲可以,但这是一个令人痛苦的事情)。
如果您使用 C#(或任何其他 .NET 语言)创建 DLL,则完全是另一回事 - 它不是 Windows DLL,它只是一个没有入口点(Main)的 .Net 程序集,因此可以从其他 .NET 使用它通过引用 DLL 来引用程序集。
总结一下:
如果您需要使用 .NET 语言中的 DLL - 用 C# 编写它,它不会是 Windows DLL,而只是一个程序集。非常容易使用。
如果您需要仅从 C++ 中使用 DLL,并且仅从同一编译器编写的应用程序中使用 DLL,请使用 C++ 编写。不便于携带,但易于使用。
如果您想创建一个可以在 .NET、C、C++ 中使用且不考虑编译器的通用库,请使用标记为 extern“C” 并具有类似 C 参数的 C 或 C++ 独立函数,就像指针和 POD 一样。
华泰
A DLL is best written in C :)
Let me explain:
DLL's were conceived before C++ came into mainstream use. They were created for the C language. You can write DLL's with C++ but you'll be able to easily use them only from applications that were written with the same version of the same compiler as the DLL. A C DLL can be used from .NET, unlike C++ (yeah, I know, technically it can, but it is a pain in the buttocks).
If you create DLL with C#(or any other .NET language), it's a completely other thing - it's not a windows DLL, it's just a .Net assembly without an entry point(Main), so it can be used from other .NET assemblies by referencing the DLL.
To summarize:
If you need to use your DLL from .NET languages - write it in C#, it won't be a windows dll, just an assembly. Very easy to use.
If you need to use your DLL from ONLY C++ and ONLY from applications written by the same compiler, write in C++. Not portable, easy to use.
If you want to create a general-purpose library that can be used from .NET, C, C++ and regardless of the compiler, use C, or C++ freestanding functions marked as extern "C" and having C-like parameters, like pointers and POD's.
HTH
这将取决于您的目标应用程序。如果您正在编写 Win32 应用程序,那么 C++ 可能是明智的选择。如果您正在 .NET 中开发可重用库,请选择 C#。
It will depend upon your target application. If you are writing Win32 app, then C++ may be wise choice. If you are developing a reusable library in .NET chose C#.
当您说 C++ 时,您指的是标准 C++ 还是“托管”版本?
如果您指的是后者,那么您的情况并不比用 C# 编写更糟,因为托管 C++ 是一种替代的 .NET 语言,实际上我认为您有更多可用的功能,尽管它不像 C# 那样简单编写。
When you say C++ are you referring to the Standard C++ or the "Managed" version?
If you are referring to the latter then you are no worse off than writing in C# as Managed C++ is an alternative .NET language, and actually I think you have more functionality available, although it is not as simple a language to write in as C#.
如果您指的是托管 C++,则库的优点和缺点不会改变。但对于编码来说,易用性和可用的库很重要。
我建议你使用 c#,因为你说你是新手。这要容易得多,而且您有很多在线资源。
但如果您计划使用一些本机代码并需要 CLR 支持,那么 c++ 是唯一的选择。
祝你好运
Pros and cons dont change for a library if you mean managed c++. But for the coding, ease of use and available libraries matters.
I would suggest c# since you say you are newbie. Its much more easy and you have LOTS of sources online.
But if you plan to use some native code and need CLR support then c++ is the only choice.
Good luck