阅读:1280回复:3
求助在驱动中读写文件时蓝屏
相关代码:
#define DEFAULT_LOG_FILE_NAME L\"\\\\DosDevices\\\\C:\\\\UnScanner.log\" //--------------------------------------------------------------------- BOOLEAN DVRH_LogMessage(PCHAR szFormat, ...) { ULONG Length; char messagebuf[256]; va_list va; IO_STATUS_BLOCK IoStatus; OBJECT_ATTRIBUTES objectAttributes; NTSTATUS status; HANDLE FileHandle; UNICODE_STRING fileName; //format the string va_start(va,szFormat); vsprintf(messagebuf,szFormat,va); va_end(va); //get a handle to the log file object fileName.Buffer = NULL; fileName.Length = 0; fileName.MaximumLength = sizeof(DEFAULT_LOG_FILE_NAME) + sizeof(UNICODE_NULL); fileName.Buffer = ExAllocatePool(PagedPool, fileName.MaximumLength); if (!fileName.Buffer) { //ParDump2(PARERRORS, (\"LogMessage: FAIL. ExAllocatePool Failed.\\n\") ); return FALSE; } RtlZeroMemory(fileName.Buffer, fileName.MaximumLength); status = RtlAppendUnicodeToString(&fileName, (PWSTR)DEFAULT_LOG_FILE_NAME); InitializeObjectAttributes (&objectAttributes, (PUNICODE_STRING)&fileName, OBJ_CASE_INSENSITIVE, NULL, NULL ); status = ZwCreateFile(&FileHandle, FILE_APPEND_DATA, &objectAttributes, &IoStatus, 0, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 ); if(NT_SUCCESS(status)) { CHAR buf[300]; LARGE_INTEGER time; KeQuerySystemTime(&time); //put a time stamp on the output message sprintf(buf,\"%10u-%10u %s\",time.HighPart,time.LowPart,messagebuf); //format the string to make sure it appends a newline carrage-return to the //end of the string. Length=strlen(buf); if(buf[Length-1]==\'\\n\') { buf[Length-1]=\'\\r\'; strcat(buf,\"\\n\"); Length++; } else { strcat(buf,\"\\r\\n\"); Length+=2; } ZwWriteFile(FileHandle, NULL, NULL, NULL, &IoStatus, buf, Length, NULL, NULL ); ZwClose(FileHandle); } if (fileName.Buffer) ExFreePool (fileName.Buffer); return STATUS_SUCCESS; } //--------------------------------------------------------------------- //上面的函数是从DDK例子debug.c中copy过来的 //当执行下面的语句时回导致系统蓝屏 char logMsg[64]; sprintf(logMsg, \"%d\", * (int *)(PacketBuffer + 26)); DVRH_LogMessage(logMsg); //本人是刚开始学驱动开发,找不到资料 //所以还望高手指点一下 |
|
最新喜欢:cyliu |
沙发#
发布于:2003-12-16 21:23
我的函数调用格式是错的
|
|
板凳#
发布于:2005-02-03 19:38
楼主,可否把解决方法贴出来阿
|
|
|
地板#
发布于:2005-02-04 11:07
//put a time stamp on the output message
sprintf(buf,"%10u-%10u %s",time.HighPart,time.LowPart,messagebuf); //format the string to make sure it appends a newline carrage-return to the //end of the string. Length=strlen(buf); if(buf[Length-1]=='\n') { buf[Length-1]='\r'; strcat(buf,"\n"); Length++; } else { strcat(buf,"\r\n"); Length+=2; } 把上面一段换成内核函数试试!我以前用C库也兰过屏!! 不知对不对 |
|