学习了2个月时间 走了不少弯路 现奉上搜集到的驱动开发入门笔记 共勉!

源代码在线查看: control.cpp

软件大小: 7376 K
上传用户: lqlm521
关键词: 驱动开发
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Control.cpp -- IOCTL handlers for usb42 driver
				// Copyright (C) 1999 by Walter Oney
				// All rights reserved
				
				#include "stddcls.h"
				#include "driver.h"
				#include "ioctls.h"
				
				///////////////////////////////////////////////////////////////////////////////
				
				#pragma PAGEDCODE
				
				NTSTATUS DispatchControl(PDEVICE_OBJECT fdo, PIRP Irp)
					{							// DispatchControl
					PAGED_CODE();
					PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension;
				
					NTSTATUS status = IoAcquireRemoveLock(&pdx->RemoveLock, Irp);
					if (!NT_SUCCESS(status))
						return CompleteRequest(Irp, status, 0);
					ULONG info = 0;
				
					PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
					ULONG cbin = stack->Parameters.DeviceIoControl.InputBufferLength;
					ULONG cbout = stack->Parameters.DeviceIoControl.OutputBufferLength;
					ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
				
					switch (code)
						{						// process request
				
					case IOCTL_USB42_READ:
						{						// IOCTL_USB42_READ
						if (cbout != 64)
							{
							status = STATUS_INVALID_PARAMETER;
							break;
							}
				
						URB urb;
						UsbBuildInterruptOrBulkTransferRequest(&urb, sizeof(_URB_BULK_OR_INTERRUPT_TRANSFER),
							pdx->hpipe, Irp->AssociatedIrp.SystemBuffer, NULL, cbout, USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, NULL);
						status = SendAwaitUrb(fdo, &urb);
						if (!NT_SUCCESS(status))
							KdPrint(("USB42 - Error %X (USBD status code %X) trying to read endpoint\n", status, urb.UrbHeader.Status));
						else
							info = cbout;
						break;
						}						// IOCTL_USB42_READ
				
					default:
						status = STATUS_INVALID_DEVICE_REQUEST;
						break;
				
						}						// process request
				
					IoReleaseRemoveLock(&pdx->RemoveLock, Irp);
					return CompleteRequest(Irp, status, info);
					}							// DispatchControl
				
							

相关资源