Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

So, with the latest version of Delphi (2010), would it be technically possible to write a Windows driver?

like image 311
Mick Avatar asked Feb 15 '10 00:02

Mick


People also ask

How do I create a driver in Windows 10?

Select and hold (or right-click) the driver project and choose Properties. Under Configuration Properties->Driver, verify that Target Platform is set to Windows Drivers. To build a driver that runs on Windows 10 for Desktop editions only, select Desktop. Build the driver.

How do I create a driver project in Visual Studio?

Create and build a driver. Open Microsoft Visual Studio. On the File menu, choose New > Project. In the Create a new project dialog box, select C++ in the left dropdown, choose Windows in the middle dropdown, and choose Driver in the right dropdown.


2 Answers

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.

First, there's a difference between user-mode driver (UMDF) drivers and kernel-mode (KMDF) drivers. UMDF drivers should be possible with Delphi. KMDF drivers aren't easily possible though, because

1) Delphi's linker can't produce them and

2) Delphi's object file format is different from the COFF format the Microsoft linker uses by default.

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 e.g. 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. There are also difficulties with System and SysInit units (see the comment by Ritsaert Hornstra to another answer here).

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. Since currently, there is no 64-bit Delphi compiler, writing them is a definite no-no.

like image 50
PhiS Avatar answered Sep 22 '22 01:09

PhiS


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.

The no-unapproved-external-dependencies is going to be the hard part I would think. :)

like image 26
John Knoeller Avatar answered Sep 23 '22 01:09

John Knoeller