+ -
当前位置:首页 → 问答吧 → Delphi和驱动通信的问题

Delphi和驱动通信的问题

时间:2011-10-12

来源:互联网

用户层如何接受R0的缓冲区字符串类型的数据呢?
KdPrint(("[Irp->AssociatedIrp.SystemBuffer_Data]: %s\n", *(ULONG*)ioBuffer)); 
-----
WinDbg输出:
[Irp->AssociatedIrp.SystemBuffer_Data]: C:\Documents and Settings\Administrator\桌面\Project1.exe
-----------
ReadFile或者DeviceIoControl


我在DP这样写不行
我已经在R0将字符串传递给了缓冲区。

procedure TForm1.btn3Click(Sender: TObject);
var

 BytesReturned : DWORD;
 ret : Boolean;
 SendData: DWORD;
 RecoyData: String;
begin
  SendData:=0;
ret := DeviceIoControl(
  m_hCommDevice,
IOCTL_EXTNDDRV_GET_STARTING_SERVICEID, //dwIoControlCode
@SendData,
0,
@RecoyData, //接受的数据
sizeof(RecoyData), //缓冲区大小设置
BytesReturned, //实际接受到的数据大小
nil);
  //BytesReturned:= sizeof(RecoyData);
  label1.Caption:= 'DeviceIoControl Run Over';

  label1.Caption:= IntToStr(BytesReturned);


  if ret = False then label1.Caption:= 'Operation failed';

if (ret = True) then
  begin
  //if (BytesReturned <> sizeof(RecoyData)) then
  // begin
  // label1.Caption:= 'Buffer Space Error,or Buffer Size Too short';
// ret := FALSE;
  // end
  // else
  //begin
  // label1.Caption:= 'Operation success!';
  //edt2.Text := IntToStr(RecoyData);
  edt2.Text := RecoyData;

   
  ret := TRUE;
  end;
  end;
end;
-------

作者: xedazss   发布时间: 2011-10-12

第一,你的接收使用了阻塞式,第二、在主线程就收。

建议不要这样做,可以借鉴spcomm控件的手法,使用线程循环监控、异步通讯(非阻塞式),用事件驱动。

作者: gzzai   发布时间: 2011-10-12

热门下载

更多