Write a VXD device driver with Delphi
Introduction Windows has two types of VXD device drivers: 1, static VXD, load the operating system and permanently exist in memory; 2, dynamic vxd, when needed, transfer to memory, use After closing the VXD, you can release the memory. Inprise Delphi has the ability to build any type of VXD device driver. Here we will show how to establish dynamic VXD. When the Win32 application opens a VXD "virtual" device, VWIN32 loads VXD into memory with loadDevice, and establishes a message W32_DeviceioControl, and send VXD. That is, it should respond vxd least two of the following system information and a function to write the following: sys_dynamic_device_init sys_dynamic_device_exit w32_deviceiocontrol sys_dynamic_device_init message sent to the function when attempting to load vxd vxd, sys_dynamic_device_exit message sent when trying to vxd dynamic exchange of messages. After the handle is successfully processed, the VXD_SUCCESS flag should be returned in the register AX. The DWService parameter of W32_Deviceiocontrol has the following values: DIOC_OPEN When VXD is sent (after the Sys_Dynamic_Device_init message attempts to open the operation, if the sys_dynamic_Device_init message is successfully returned to NO_ERROR (0); dioc_closehandle When VXD is sent via a closehandle () function attempts to shut down the operation (Before Sys_Dynamic_Device_exit) All other values> 0 means different function calls (given by dwiocontrolcode), when VXD is called by DeviceIocontrol function.
Start Module (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 Chkdeviock 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 will call the external process HandleFinal and Initialization, even if INITIALALIZATION / Finalization does not exist in the unit. Therefore, we build an empty external process entrance in the assembled launch file.
Delphi main program unit (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: POIN ter): 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; Else Begin Result: = VXD_SUCCESS; End; End; ... [Translator: Ok, Simple VXD device driver has completed. You can treat it as a template for writing a VXD device driver.