怎么用delphi些vxd程序?哪有这方面的资料?最好是纯delphi的。 很遗憾,DELPHI 不适合做硬件驱动。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 vxd好像是M$专利的格式,他不让人家的开放工具编译出vxd文件,所以:-(xxxM$ 前言 用 delphi 3.0 编写 vxd 设备驱动程序,在delphi 3 下编译通过,delphi 2 下没有测试,delphi 4 建立的 object 文件 m$ linker 5.12.8181 不能识别,这里使用的汇编器是m$的macro assembler ver. 6.11d ,联结器是m$ incremental linker ver. 5.12.8181 ,它们来自 windows 98ddk(http://www.microsoft.com/ddk/ddk98.htm)。 介绍 windows 存在有两种类型的 vxd 设备驱动程序: 1、静态(static) vxd ,装入操作系统并永久的存在于内存中; 2、动态(dynamic) vxd,当需要时才调入内存,用完后关闭vxd即可释放内存。 inprise delphi 有能力建立任何一种类型的 vxd 设备驱动程序,下面我们将介绍如何建立动态 vxd。 当 win32 应用程序打开一个 vxd “虚拟”设备时,vwin32 使用 loaddevice 将 vxd 装入内存,并建立消息w32_deviceiocontrol ,发向 vxd。 也就是说,vxd 至少应该响应以下两个系统信息和编写以下的一个函数: sys_dynamic_device_init sys_dynamic_device_exit w32_deviceiocontrol 函数. 消息 sys_dynamic_device_init 在尝试装入 vxd 时发送到 vxd ,消息 sys_dynamic_device_exit 在尝试动态交换时发送到 vxd ,消息的处理者在成功处理后,应该在寄存器 ax 中返回 vxd_success 标志。 w32_deviceiocontrol 的 dwservice 参数有以下的值: dioc_open 当 vxd 通过 createfile() 函数尝试打开操作时发送(在 sys_dynamic_device_init 消息后),如果成功返回 no_error (0); dioc_closehandle 当 vxd 通过 closehandle() 函数尝试关闭操作时发送(在 sys_dynamic_device_exit 前) 所有其它的值 > 0 意味着不同的函数调用(由 dwiocontrolcode 给出),当 vxd 被 deviceiocontrol 函数调用时。 启动模块(vxdmain.asm) ... extrn sysdynamicdeviceinit :proc extrn sysdynamicdeviceexit :proc extrn w32deviceiocontrol :proc ... public delphiio_ddb public @@handlefinally public @initialization ... control_0 proc cmp eax, sys_dynamic_device_init jnz short chksysdynexit call sysdynamicdeviceinit cmp eax, 1 retn ;------------- chksysdynexit: cmp eax, sys_dynamic_device_exit jnz short chkdevioctl call sysdynamicdeviceexit cmp eax, 1 retn ;------------- chkdevioctl: cmp eax, w32_deviceiocontrol jnz short loc_ret push esi push edx push ebx push ecx call w32deviceiocontrol cmp eax, 1 retn ;------------- loc_ret: clc retn control_0 endp @@handlefinally: @initialization: ret _ltext ends end delphi 会为单元的 initialization/finalization 建立代码调用外部过程 handlefinaly 和 initialization ,即使 initialization/finalization 在单元中不存在。因此我们在汇编的启动文件中建立空的外部过程入口。 主 delphi 程序单元(vxdprocs.pas) ... procedure shellmessage(handle, flags : integer; const message, caption : pchar; callback, referencedata : pointer); stdcall; assembler; asm mov ebx, handle // virtual machine handle mov eax, flags // message box flags mov ecx, message // address of message text mov edi, caption // address of caption text mov esi, callback // address of callback mov edx, referencedata // reference data for callback int 20h // vxdcall dd 170004h // shell_message end; function sysdynamicdeviceinit : integer; begin shellmessage(0, $10, copyright, ’sysdyninit: hello from delphi vxd !!!’, nil, nil); result := vxd_success; end; function sysdynamicdeviceexit : integer; begin shellmessage(0, $10, copyright, ’sysdyndevexit: bye from delphi vxd !!!’, nil, nil); result := vxd_success; end; function w32deviceiocontrol(dwservice : integer; dwddb : integer; hdevice : integer; lpdiocparms : pointer) : integer; begin shellmessage(0, $10, copyright, ’w32devioctl’, nil, nil); if (dwservice = dioc_open) then begin result := no_error; end else if (dwservice = dioc_closehandle) then begin result := vxd_success; end else if (dwservice > max_pasvxd_w32_api) then begin result := error_not_supported; end else begin result := vxd_success; end; end; ... [译者:好了,简单的 vxd 设备驱动程序编写完毕了。你可以将它当作一个写 vxd 设备驱动程序的模板。] 附一:make.bat d:\visual~1\98ddk\bin\win98\ml -coff -dbld_coff -dis_32 -w2 -c -cx -zm -dmasm6 vxdmain.asm call dcc3.bat -j vxdprocs.pas d:\visual~1\98ddk\bin\link /def:vxddef.def /vxd vxdmain.obj vxdprocs /out:delphiio.vxd 附二: 现在让我们来编写对该 vxd 的测试程序,两个按钮:一个打开 vxd;一个关闭 vxd。 const vxdname = ’\\.\delphiio.vxd’; ... function tvxdtestform.openvxddriver: boolean; begin hvxdhandle := createfile(vxdname,0,0,nil,0,file_flag_delete_on_close,0); result := hvxdhandle <> invalid_handle_value; end; procedure tvxdtestform.closevxddriver; begin if hvxdhandle <> invalid_handle_value then begin closehandle(hvxdhandle); hvxdhandle := invalid_handle_value; end; end 顺便说一下,delphi中有个编译选项可以控制程序加载的入口 一般是0x00400000,你可以改。 求 DELPHI 下二维条码控制 寻求help&maunal高手指导 GLScene帮助,中英文对照 paradox的blob数据列不可见的问题 数据更新难题 请问怎样改变BMP的颜色? 这个问题,在我脑中都创建了1000个“线程”了,快崩溃了 关于年度精华贴 明天过双休,爽!散分。五点半结账。 急 帮忙 20 DELPHID在不同平台上显示为什么会不同, 有没有一个好的办法来显示的比较好一些,高分送给!! 如何设置Filed的defaultExpression,使之能自动填写默认值?
xxxM$
介绍 windows 存在有两种类型的 vxd 设备驱动程序: 1、静态(static) vxd ,装入操作系统并永久的存在于内存中;
2、动态(dynamic) vxd,当需要时才调入内存,用完后关闭vxd即可释放内存。 inprise delphi 有能力建立任何一种类型的 vxd 设备驱动程序,下面我们将介绍如何建立动态 vxd。 当 win32 应用程序打开一个 vxd “虚拟”设备时,vwin32 使用 loaddevice 将 vxd 装入内存,并建立消息w32_deviceiocontrol ,发向 vxd。 也就是说,vxd 至少应该响应以下两个系统信息和编写以下的一个函数: sys_dynamic_device_init
sys_dynamic_device_exit
w32_deviceiocontrol 函数. 消息 sys_dynamic_device_init 在尝试装入 vxd 时发送到 vxd ,消息 sys_dynamic_device_exit 在尝试动态交换时发送到 vxd ,消息的处理者在成功处理后,应该在寄存器 ax 中返回 vxd_success 标志。 w32_deviceiocontrol 的 dwservice 参数有以下的值: dioc_open 当 vxd 通过 createfile() 函数尝试打开操作时发送(在 sys_dynamic_device_init 消息后),如果成功返回 no_error (0); dioc_closehandle 当 vxd 通过 closehandle() 函数尝试关闭操作时发送(在 sys_dynamic_device_exit 前) 所有其它的值 > 0 意味着不同的函数调用(由 dwiocontrolcode 给出),当 vxd 被 deviceiocontrol 函数调用时。 启动模块(vxdmain.asm)
...
extrn sysdynamicdeviceinit :proc
extrn sysdynamicdeviceexit :proc
extrn w32deviceiocontrol :proc
...
public delphiio_ddb
public @@handlefinally
public @initialization
...
control_0 proc
cmp eax, sys_dynamic_device_init
jnz short chksysdynexit
call sysdynamicdeviceinit
cmp eax, 1
retn
;------------- chksysdynexit:
cmp eax, sys_dynamic_device_exit
jnz short chkdevioctl
call sysdynamicdeviceexit
cmp eax, 1
retn
;-------------
chkdevioctl:
cmp eax, w32_deviceiocontrol
jnz short loc_ret
push esi
push edx
push ebx
push ecx
call w32deviceiocontrol
cmp eax, 1
retn
;-------------
loc_ret:
clc
retn control_0 endp @@handlefinally:
@initialization:
ret _ltext ends
end
delphi 会为单元的 initialization/finalization 建立代码调用外部过程 handlefinaly 和 initialization ,即使 initialization/finalization 在单元中不存在。因此我们在汇编的启动文件中建立空的外部过程入口。 主 delphi 程序单元(vxdprocs.pas)
...
procedure shellmessage(handle, flags : integer; const message, caption : pchar;
callback, referencedata : pointer); stdcall; assembler;
asm
mov ebx, handle // virtual machine handle
mov eax, flags // message box flags
mov ecx, message // address of message text
mov edi, caption // address of caption text
mov esi, callback // address of callback
mov edx, referencedata // reference data for callback int 20h // vxdcall
dd 170004h // shell_message
end; function sysdynamicdeviceinit : integer;
begin
shellmessage(0, $10, copyright, ’sysdyninit: hello from delphi vxd !!!’, nil, nil);
result := vxd_success;
end; function sysdynamicdeviceexit : integer;
begin
shellmessage(0, $10, copyright, ’sysdyndevexit: bye from delphi vxd !!!’, nil, nil);
result := vxd_success;
end; function w32deviceiocontrol(dwservice : integer;
dwddb : integer;
hdevice : integer;
lpdiocparms : pointer) : integer;
begin
shellmessage(0, $10, copyright, ’w32devioctl’, nil, nil); if (dwservice = dioc_open) then
begin
result := no_error;
end
else if (dwservice = dioc_closehandle) then
begin
result := vxd_success;
end
else if (dwservice > max_pasvxd_w32_api) then
begin
result := error_not_supported;
end
else
begin
result := vxd_success;
end;
end;
...
[译者:好了,简单的 vxd 设备驱动程序编写完毕了。你可以将它当作一个写 vxd 设备驱动程序的模板。] 附一:make.bat d:\visual~1\98ddk\bin\win98\ml -coff -dbld_coff -dis_32 -w2 -c -cx -zm -dmasm6 vxdmain.asm
call dcc3.bat -j vxdprocs.pas
d:\visual~1\98ddk\bin\link /def:vxddef.def /vxd vxdmain.obj vxdprocs /out:delphiio.vxd 附二: 现在让我们来编写对该 vxd 的测试程序,两个按钮:一个打开 vxd;一个关闭 vxd。 const
vxdname = ’\\.\delphiio.vxd’; ... function tvxdtestform.openvxddriver: boolean;
begin
hvxdhandle := createfile(vxdname,0,0,nil,0,file_flag_delete_on_close,0);
result := hvxdhandle <> invalid_handle_value;
end; procedure tvxdtestform.closevxddriver;
begin
if hvxdhandle <> invalid_handle_value then begin
closehandle(hvxdhandle);
hvxdhandle := invalid_handle_value;
end;
end
顺便说一下,delphi中有个编译选项可以控制程序加载的入口 一般是0x00400000,你可以改。