阅读:935回复:0
大家帮帮我
我是一名驱动程序的初学者,我做了一个USB驱动程序,可是一进行读写电脑就重启,头都大了。大家谁知道这样的问题,快帮帮我
我的驱动里的Write 函数是这样的 NTSTATUS TPUSBDevice::Write(KIrp I) { T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I); NTSTATUS status = STATUS_SUCCESS; // TODO: Validate the parameters of the IRP. Replace "FALSE" // in the following line with error checking code that // evaulates to TRUE if the request is not valid. if (FALSE) { status = STATUS_INVALID_PARAMETER; I.Information() = 0; I.PnpComplete(status); T.Trace(TraceWarning, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } // Always ok to write 0 elements if (I.WriteSize() == 0) { I.Information() = 0; I.PnpComplete(this, status); T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } KMemory Mem(I.Mdl()); // Declare a memory object // Get a pointer to the caller's buffer. Note that this // routine is safe on all platforms. PUCHAR pBuffer = (PUCHAR) Mem.MapToSystemSpace(); ULONG dwTotalSize = I.WriteSize(CURRENT); ULONG dwMaxSize = PIPE02.MaximumTransferSize(); if ( dwTotalSize > dwMaxSize ) { ASSERT(dwMaxSize); dwTotalSize = dwMaxSize; } ULONG bytesSent = 0; // TODO: At this point, perform any processing for IRP_MJ_WRITE // To satisfy the write now, transfer data to the driver // from the caller's buffer at "pBuffer". Then, indicate // how much data was transferred: PURB pUrb = PIPE02.BuildBulkTransfer( Mem, // Where is data coming from? dwTotalSize, // How much data to write? FALSE, // direction (FALSE = OUT) NULL // Link to next URB ); if(pUrb !=NULL) { status = PIPE02.SubmitUrb(pUrb,NULL,NULL,100); if(status == STATUS_SUCCESS) { bytesSent = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength; } delete pUrb; } I.Information() = bytesSent; I.PnpComplete(this, status); T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } |
|