请问USB驱动开发

请教USB驱动开发
鉴于使用DriverStudio开发WDM驱动地便捷。我使用DriverWorks生成了一个具有一个中断输入,
一个中断输出端点的USB驱动程序。并且生成了Read和Write例程。

我想请问下,DS生成的Read和Write例程可以不用添加代码直接使用吗?为什么我直接使用地时候。
用应用程序读,写,还回的操作数都是0呢?

然后我查看驱动地读写例程。发现中间根本就没有URB的发送过程,操作数也是直接被赋0.于是添加了建立URB并传送URB的
代码。结果系统蓝屏了。。
一下是写地代码。其中//////////之间的代码是我添加地。请指教。

C/C++ code


NTSTATUS UsbIntDevice::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 writeSize = I.WriteSize();
    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:
    
    
    
//////////////////////////////////////////////////// Kondy Add Start
    PURB pUrb =EP2_OUT.BuildBulkTransfer(

        Mem,
        I.IoctlInputBufferSize(),
        FALSE,
        NULL);
     if(pUrb==NULL)
    {
     
        I.Information()=0;
        return I.PnpComplete(this,STATUS_INSUFFICIENT_RESOURCES);
    }
    status=EP2_OUT.SubmitUrb(pUrb,NULL,NULL,1500L);
    bytesSent=pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength; 
    ////////////////////////////////////////////////////Kondy Add End
    
    I.Information() = bytesSent;

    I.PnpComplete(this, status);

    T.Trace(TraceInfo, __FUNCTION__"--.  IRP %p, STATUS %x\n", I, status);

    return status;
}


------解决方案--------------------
不会,学习一下
------解决方案--------------------
才开始学写驱动程序,帮顶。。。
------解决方案--------------------
没写过USB驱动。
也不用DS。
但是你这个应该错了吧?可以直接返回Complete?

return I.PnpComplete(this,STATUS_INSUFFICIENT_RESOURCES);

应该是
I.PnpComplete(this,STATUS_INSUFFICIENT_RESOURCES);
return STATUS_INSUFFICIENT_RESOURCES;

这样吧。

只用记事本写过滤驱动。对 DS和USB驱动不是很了解。都是猜测。说的不对见谅。
------解决方案--------------------
还有就是你用windbg调下dump看看。
------解决方案--------------------
代码没问题,但一些DDK自带的驱动都是独立于操作系统之外的。没有考虑重叠的情况。

探讨

引用:
才开始学写驱动程序,帮顶。。。



那段代码是参考DDK 例程写地。。
应该没问题

------解决方案--------------------
mark..............
------解决方案--------------------
windbg调下dump看看。
------解决方案--------------------
不懂,初学中。。。。。。。。
------解决方案--------------------