LuckLrp54321
驱动牛犊
驱动牛犊
  • 注册日期2004-05-09
  • 最后登录2007-01-03
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1079回复:1

DeviceIoControl函数问题

楼主#
更多 发布于:2005-04-21 08:45
我写了一驱动程序,应用程序调用DeviceIoControl函数接受数据却只能得到4个字节(我是想得到5个字节).请各位指点,谢谢!
应用程序代码:
    ......
    typedef struct OutParaStruct{
       UCHAR Flag;
       UCHAR PciConfig[64];
       }OutParaStruct,*POutParaStruct;
    OutParaStruct RetInforma;
    RetInforma.Flag=0;
    for(int i=0;i<65;i++)
 RetInforma.PciConfig=0;
    DWORD  OutBuffer;
  
  DWORD Returned;

  HANDLE   hDevice;
  hDevice = CreateFile( \"\\\\\\\\.\\\\MyDevice\",
                          GENERIC_READ | GENERIC_WRITE,
                          0,
                          NULL,
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL
                          );
  bool ret;
  long ConfigPara;
    for(long BusNumber=0;BusNumber<4;BusNumber++)
 for(long DevNumber=0;DevNumber<32;DevNumber++)
 for(long FuncNumber=0;FuncNumber<8;FuncNumber++)
 {
 ConfigPara=(0x80<<24)|(BusNumber<<16)|(DevNumber<<11)|(FuncNumber<<8)|(0x0<<2);
     bool ret=DeviceIoControl(hDevice,IOCTL_GET_VALUE,(LPVOID)&ConfigPara,(DWORD)65,(LPVOID)&RetInforma,(DWORD)65,&Returned,NULL);
     if((int)(BYTE)RetInforma.Flag==true)
 {
 }
 }



驱动程序代码:
   UCHAR OutParaBuffer[65];
   NTSTATUS TestWDMIoControl(IN PDEVICE_OBJECT fdo,IN PIRP irp)
{
    PIO_STACK_LOCATION IrpStack=IoGetCurrentIrpStackLocation(irp);
    ULONG ControlCode=IrpStack->Parameters.DeviceIoControl.IoControlCode;
    
  
    for(int i=0;i<65;i++)
        OutParaBuffer=0x0;
    PVOID inputBuffer, outputBuffer;
    ULONG inputBufferLength, outputBufferLength;
    ULONG ioControlCode;

   //get Buffer\'s Positon & length.
    inputBuffer = irp->AssociatedIrp.SystemBuffer;
    inputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
    outputBuffer = irp->AssociatedIrp.SystemBuffer;
    outputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
    
    ULONG ConfigData;
    ULONG VenDevID;
    USHORT VendorID,DeviceID;
    ULONG ConfigAddrPortAddress;
    ULONG ConfigDataPortAddress;
    
    switch(ControlCode)
    {
     case IOCTL_GET_VALUE:      
        __asm{
        pusha
        mov eax,[ebp+0xc]
        mov ebx,[eax+0xc]
        mov eax,[ebx]
        mov ConfigData,eax
        mov eax,ConfigData
        mov dx,0xcf8
        out dx,eax
        mov dx,0xcfc
        in eax,dx
        cmp ax,0xffff
        jz lable1
        mov VenDevID,eax
        mov  VendorID,ax
        shr eax,16
        mov  DeviceID,ax
lable1: popa
        }
        if((VendorID)!=0xffff)
        {
         OutParaBuffer[0]=0x1;
         OutParaBuffer[1]=(UCHAR)VenDevID;
         OutParaBuffer[2]=(UCHAR)(VenDevID>>8);
         OutParaBuffer[3]=(UCHAR)(VenDevID>>16);
         OutParaBuffer[4]=(UCHAR)(VenDevID>>24);
           __asm{
         pusha
        
           popa
                }
                
                
                RtlCopyMemory(irp->AssociatedIrp.SystemBuffer,OutParaBuffer,outputBufferLength);
        }
        
      
      
        
        break;

    
     default:
     break;
    
    
    };
    irp->IoStatus.Status=STATUS_SUCCESS;
    irp->IoStatus.Information=sizeof(ULONG);
    IoCompleteRequest(irp,IO_NO_INCREMENT);
    return STATUS_SUCCESS;
}
Nsun
驱动牛犊
驱动牛犊
  • 注册日期2004-03-04
  • 最后登录2006-09-23
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-04-21 09:09
irp->IoStatus.Information=sizeof(ULONG);
~~~~~~~~~~~~~~~~~~~~~~~~~
这个指示I/O管理器需要copy到用户地址空间的字节数.改成
irp->IoStatus.Information=sizeof(ULONG)+1;
游客

返回顶部