帮忙看看,这个小程序一装就死,不知哪里有错

yyii 2004-09-15 11:46:44
st1.h文件如下:

#ifndef ST1_H
#define ST1_H

DEFINE_GUID(ST1_GUID, 0xeef3eafe, 0x56bd, 0x4806, 0xab, 0xa0, 0xf, 0x7b, 0xce, 0x76, 0x59, 0xf8);

typedef struct _ST1_DEVICE_EXTENSION{
DEVICE_OBJECT *pfdo;
DEVICE_OBJECT *pNextStackDevice;
UNICODE_STRING SymbolLinkName;
}ST1_DEVICE_EXTENSION;

void st1Unload(DRIVER_OBJECT *pDriver_Object);
long st1AddDevice(DRIVER_OBJECT *pDriver_Object, DEVICE_OBJECT *ppdo);
long st1Pnp(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1Power(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1Create(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1Close(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1Read(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1Write(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1DeviceControl(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1SystemControl(DEVICE_OBJECT *pfdo, IRP *pIrp);
long st1CompleteIrp(IRP *pIrp, long status, unsigned long info);

#endif

st1.c文件内容如下:

#define INITGUID

#ifdef __cplusplus
extern "C"{
#endif

#include "wdm.h"

#ifdef __cplusplus
}
#endif

//#include "debugprint.h"
#include "st1.h"

/*#if DBG
#define DbgPrint(x) DebugPrint x
#define DbgPrintInit(x) DebugPrintInit x
#define DbgPrintClose DebugPrintClose
#else
#define DbgPrint(x)
#define DbgPrintInit(x)
#define DbgPrintClose()
#endif*/

long
DriverEntry(DRIVER_OBJECT *pDriverObject, UNICODE_STRING *RegistryPath){
long status;

status = STATUS_SUCCESS;
//DbgPrintInit(("st1 driver entered"));
//DbgPrint(("register path is %T", RegistryPath));

pDriverObject->DriverExtension->AddDevice = st1AddDevice;
pDriverObject->DriverUnload = st1Unload;

pDriverObject->MajorFunction[IRP_MJ_PNP] = st1Pnp;
pDriverObject->MajorFunction[IRP_MJ_POWER] = st1Power;
pDriverObject->MajorFunction[IRP_MJ_CREATE] = st1Create;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = st1Close;
//pDriverObject->MajorFunction[IRP_MJ_READ] = st1Read;
//pDriverObject->MajorFunction[IRP_MJ_WRITE] = st1Write;
pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = st1SystemControl;
//pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = st1DeviceControl;
return (status);
}

void
st1Unload(DRIVER_OBJECT *pDriver_Object){
//DbgPrint(("st1 driver unload"));
//DbgPrintClose();
}

long
st1AddDevice(DRIVER_OBJECT *pDriver_Object, DEVICE_OBJECT *ppdo){
long status;
DEVICE_OBJECT *pfdo;
ST1_DEVICE_EXTENSION *dx;

status = STATUS_SUCCESS;
//DbgPrint(("st1 add device"));

status = IoCreateDevice(pDriver_Object,
sizeof(ST1_DEVICE_EXTENSION),
NULL,
FILE_DEVICE_UNKNOWN,
0,
FALSE,
&pfdo);
if (STATUS_SUCCESS != status){
return (status);
}
dx = (ST1_DEVICE_EXTENSION *)pfdo->DeviceObjectExtension;
dx->pfdo = pfdo;

status = IoRegisterDeviceInterface(ppdo,
&ST1_GUID,
NULL,
&dx->SymbolLinkName);
if (STATUS_SUCCESS != status){
IoDeleteDevice(pfdo);
return (status);
}
IoSetDeviceInterfaceState(&dx->SymbolLinkName, TRUE);
dx->pNextStackDevice = IoAttachDeviceToDeviceStack(pfdo, ppdo);

pfdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
pfdo->Flags &= ~DO_DEVICE_INITIALIZING;
return (status);
}

long
st1Pnp(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;
ST1_DEVICE_EXTENSION *dx;
IO_STACK_LOCATION *IrpStack;
unsigned long IrpMinorFunction;

dx = (ST1_DEVICE_EXTENSION *)pfdo->DeviceExtension;
IrpStack = IoGetCurrentIrpStackLocation(pIrp);
IrpMinorFunction = IrpStack->MinorFunction;
//DbgPrint(("st1 pnp, minorfunction is %u", IrpMinorFunction));
IoSkipCurrentIrpStackLocation(pIrp);
status = IoCallDriver(dx->pNextStackDevice, pIrp);

switch (IrpMinorFunction){
case IRP_MN_REMOVE_DEVICE:
//DbgPrint(("st1 pnp minor function IRP_MN_REMOVE_DEVICE called"));
IoSetDeviceInterfaceState(&dx->SymbolLinkName, FALSE);
RtlFreeUnicodeString(&dx->SymbolLinkName);
if (dx->pNextStackDevice)
IoDetachDevice(dx->pNextStackDevice);
IoDeleteDevice(pfdo);
break;
}
return (status);
}

long
st1Power(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;
ST1_DEVICE_EXTENSION *dx;

dx = (ST1_DEVICE_EXTENSION *)pfdo->DeviceExtension;
//DbgPrint(("st1 pnp power"));

PoStartNextPowerIrp(pIrp);
IoSkipCurrentIrpStackLocation(pIrp);
status = PoCallDriver(dx->pNextStackDevice, pIrp);
return (status);
}

long
st1Create(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;
IO_STACK_LOCATION *IrpStack;

status = STATUS_SUCCESS;
IrpStack = IoGetCurrentIrpStackLocation(pIrp);
//DbgPrint(("st1 dispatch create, filename is %T", IrpStack->FileObject->FileName));
return st1CompleteIrp(pIrp, status, 0);
}

long
st1Close(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;

status = STATUS_SUCCESS;
//DbgPrint(("st1 dispatch close"));
return st1CompleteIrp(pIrp, status, 0);
}

long
st1Read(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;

status = STATUS_SUCCESS;
return (status);
}

long
st1Write(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;

status = STATUS_SUCCESS;
return (status);
}

long
st1DeviceControl(DEVICE_OBJECT *pfdo, IRP *pIrp){
long status;

status = STATUS_SUCCESS;
return (status);
}

long
st1SystemControl(DEVICE_OBJECT *pfdo, IRP *pIrp){
ST1_DEVICE_EXTENSION *dx;

dx = (ST1_DEVICE_EXTENSION *)pfdo->DeviceExtension;
IoSkipCurrentIrpStackLocation(pIrp);
return (IoCallDriver(dx->pNextStackDevice, pIrp));
}

long
st1CompleteIrp(IRP *pIrp, long status, unsigned long info){
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = info;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return (status);
}
...全文
104 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TimiXu 2004-09-20
  • 打赏
  • 举报
回复
驱动支持读写IPR,但是stlRead和strWrite里没有完成IRP的处理啊。
rzsheng 2004-09-16
  • 打赏
  • 举报
回复
程序太多,提点意见。
一般是内存问题,察看指针,是否指向的内容已经为空!

21,616

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧