帮忙看看,这个小程序一装就死,不知哪里有错
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);
}