如何使用CreateFile访问物理磁盘?
我在 Lazarus 编程论坛上询问如何打开物理磁盘。我想允许用户在单击“选择磁盘”按钮时从系统中选择物理磁盘。 Stack Overflow 上有一些类似但不完全相同的示例(例如 Delphi - 使用 DeviceIoControl 传递 IOCTL_DISK_GET_LENGTH_INFO 来获取闪存介质物理大小(不是分区))。
有很多使用 CreateFile
的 C 和 C++ 示例 (在文档中,尤其是调用 DeviceIoControl 的示例
),但我找不到 Free Pascal 或 Delphi 的任何内容,而且我还不够好,无法弄清楚如何做到这一点。
谁能给我指出一个解释它的链接的方向,或者更好的是用 Delphi 或 Free Pascal 编写的实际示例?谁能帮助我了解如何使用它?
I asked on the Lazarus programming forum how to open a physical disk. I want to allow the user to select physical disks from their system when they click a "Select Disk" button. There are some examples here at Stack Overflow that are similar but not quite the same (such as Delphi - Using DeviceIoControl passing IOCTL_DISK_GET_LENGTH_INFO to get flash media physical size (Not Partition)).
There are lots of C and C++ examples of using CreateFile
(in the documentation and especially an example of calling DeviceIoControl
) but I can't find any for Free Pascal or Delphi and I am not good enough yet to work out how to do it.
Can anyone point me in the direction of a link that explains it or better still an actual example written in Delphi or Free Pascal? Can anyone help me understand how to use it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 C 示例具有以下代码:
将函数调用转换为 Delphi 只需更改语法即可:
也就是说,使用
:=
进行赋值,使用or
组合位标志,nil
表示空指针,0
表示空文件句柄。该函数的调用方式如下:
再次,只需将语法更改为 Delphi:
Delphi 无类型字符串常量会自动成为它们在上下文中需要的任何类型,因此我们不需要像 C 使用的任何
L
前缀。反斜杠在 Delphi 中并不特殊,因此不需要转义它们。 Delphi 不允许在声明中初始化局部变量,因此我们使用 ZeroMemory 将所有内容设置为零。使用@
而不是&
来获取指向变量的指针。Your C example has this code:
Converting that function call to Delphi is just a matter of changing the syntax:
That is, use
:=
for assignment,or
for combining bit flags,nil
for null pointers, and0
for null file handles.The function is called with this:
Again, just change the syntax to Delphi:
Delphi untyped string constants are automatically whatever type they need to be in context, so we don't need any
L
prefix like C uses. Backslashes aren't special in Delphi, so they don't need to be escaped. Delphi doesn't allow initializing local variables in the declaration, so we useZeroMemory
to set everything to zero. Use@
instead of&
to get a pointer to a variable.