简体   繁体   English

我可以用Delphi 2010编写Windows驱动程序吗?

[英]Can I write Windows drivers with Delphi 2010?

I've always heard that Delphi can do almost anything C++ can do...except write Windows drivers. 我一直听说Delphi可以做任何C ++可以做的事情......除了编写Windows驱动程序。 Is this correct, and if so, why is that? 这是正确的,如果是这样,那为什么呢?

I recently read a blog post online that may indicate a possible solution for writing drivers with Delphi , but it's 3 years old and I don't know how accurate this information is. 我最近在线阅读了一篇博客文章,可能表明使用Delphi编写驱动程序可能解决方案 ,但它已经3年了,我不知道这些信息有多准确。

So, with the latest version of Delphi (2010), would it be technically possible to write a Windows driver? 因此,使用最新版本的Delphi(2010),编写Windows驱动程序在技术上是否可行?

It may be technically possible to write some drivers with Delphi, but as far as a general answer goes, I'd say: you can't easily write drivers with Delphi . 在技​​术上可能用Delphi编写一些驱动程序,但就一般答案而言,我会说: 你不能轻易地用Delphi编写驱动程序

First, there's a difference between user-mode driver (UMDF) drivers and kernel-mode (KMDF) drivers. 首先,用户模式驱动程序(UMDF)驱动程序和内核模式(KMDF)驱动程序之间存在差异。 UMDF drivers should be possible with Delphi. 使用Delphi可以实现UMDF驱动程序。 KMDF drivers aren't easily possible though, because 但是,KMDF司机并不容易实现,因为

1) Delphi's linker can't produce them and 1)Delphi的链接器不能生成它们

2) Delphi's object file format is different from the COFF format the Microsoft linker uses by default. 2)Delphi的目标文件格式与Microsoft链接器默认使用的COFF格式不同。

3) Delphi's RTL makes the assumption it lives in user-mode and may do certain things that one shouldn't do in kernel-land (I think eg of the way exceptions are handled; also different memory management), so you'd have to be very careful on which RTL functions are safe to use. 3)Delphi的RTL假设它处于用户模式并且可能做某些不应该在kernel-land中做的事情(我认为例如处理异常的方式;也有不同的内存管理),所以你有要非常小心哪些RTL功能可以安全使用。 There are also difficulties with System and SysInit units (see the comment by Ritsaert Hornstra to another answer here). 系统和SysInit单元也存在困难(请参阅Ritsaert Hornstra的评论到另一个答案)。

I'm not saying these aren't problems that cannot be overcome (cf. the post you link to) if you're really dedicated, but it won't be straightforward. 我不是说这些不是无法克服的问题(参见你链接的帖子)如果你真的很专注,但它不会直截了当。

Secondly, KMDF drivers (I don't know about UMDF, actually - can anyone comment?) for Win64 have to be in 64-bit code. 其次,KMDF驱动程序(我不知道UMDF,实际上 - 任何人都可以发表评论吗?)因为Win64必须使用64位代码。 Since currently, there is no 64-bit Delphi compiler, writing them is a definite no-no. 从目前开始,没有64位Delphi编译器,编写它们是一个明确的禁忌。

You can write a Windows driver in any language that compiles down to a DLL in PE format, that has no external dependencies (other than those approved for loading in the kernel), can call functions with STDCALL linkage, and export functions with STDCALL linkage. 您可以使用任何语言编写Windows驱动程序,这些语言编译为PE格式的DLL,没有外部依赖关系(除了批准在内核中加载的那些),可以使用STDCALL链接调用函数,并使用STDCALL链接导出函数。

The no-unapproved-external-dependencies is going to be the hard part I would think. 没有未经批准的外部依赖性将是我想到的困难部分。 :) :)

I agree with both previous answers. 我同意以前的答案。 I've actually done it in a special case: A print monitor. 我实际上是在一个特殊情况下完成的:打印显示器。 It's a special case of driver that runs in user mode, and I could write one in Delphi. 这是一个在用户模式下运行的驱动程序的特例,我可以在Delphi中编写一个。 There was definitely some benefits in using Delphi there. 在那里使用Delphi肯定有一些好处。

But the last pitfall that wasn't mentioned yet (I think) is that you need to translate zillions of complex structures and macros from DDK header files. 但是尚未提及的最后一个陷阱(我认为)是你需要从DDK头文件中翻译数以万亿的复杂结构和宏。 Translating some convoluted macros, in particular, can be very tricky. 特别是翻译一些复杂的宏可能非常棘手。

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

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