阅读:913回复:1
大虾们看看这小段代码,是否有错??
调用以下函数时:(用于创建一个磁盘文件)
VOID MyDriverCreateFile( IN PVOID Context, IN OUT HANDLE *FileHandle, IN PSTR FileName) { NTSTATUS ntStatus; NT::OBJECT_ATTRIBUTES ObjectAttributes; NT::POBJECT_ATTRIBUTES pObjectAttributes; NT::IO_STATUS_BLOCK IoStatusBlock; NT::UNICODE_STRING UniFileName; NT::ANSI_STRING m_AnsiFileName; NT::PFILE_WORK_ITEM workitem; DBGPRINT("In MyDriverCreateFlen"); pObjectAttributes = &ObjectAttributes; NT::RtlInitAnsiString(&m_AnsiFileName,FileName); ULONG level = NT::KeGetCurrentIrql(); if(level < DISPATCH_LEVEL) { DBGPRINT("level < DISPATCH_LEVEL"); DbgPrint("level:%un",level); ntStatus = NT::RtlAnsiStringToUnicodeString(&UniFileName , &m_AnsiFileName ,TRUE); if(!NT_SUCCESS(ntStatus)) return; DbgPrint("myUniFileName:%sn",UniFileName); InitializeObjectAttributes(pObjectAttributes,&UniFileName,OBJ_CASE_INSENSITIVE,NULL,NULL); DbgPrint("pObjectAttributes->ObjectName:%sn",pObjectAttributes->ObjectName); ntStatus=NT::ZwCreateFile(FileHandle, GENERIC_WRITE | SYNCHRONIZE | FILE_APPEND_DATA, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); DbgPrint("myfilehandle:%sn",FileHandle); if(NT_SUCCESS(ntStatus) && FileHandle != NULL) { return; } } return ; }(over) 我的filename是如下初始化的: PSTR m_gFileName = "\\\\??\\\\C:\\\\passthru.dat"; 编译是对的,也可以运行,就是结果不对,症状如下: 调试语句DbgPrint("myUniFileName:%sn",UniFileName);显示myUniFileName:\\??\\C:\\passthru.dat 调试语句DbgPrint("pObjectAttributes->ObjectName:%sn",pObjectAttributes->ObjectName);显示 pObjectAttributes->ObjectName:pObjectAttributes->ObjectName:& 调试语句DbgPrint("myfilehandle:%sn",FileHandle);显示 myfilehandle:(null)说明文件没有创建... 这个问题缠绕我好久了,偶第一次做驱动,以上所有函数都是第一次 用,请大虾们不吝赐教,谢谢啦~~~~~~~~~~ [编辑 - 8/11/04 by Camus1981] [编辑 - 8/11/04 by Camus1981] [编辑 - 8/11/04 by Camus1981] [编辑 - 8/11/04 by Camus1981] |
|
沙发#
发布于:2004-08-12 08:32
调试语句DbgPrint("pObjectAttributes->ObjectName:%sn",pObjectAttributes->ObjectName);显示
pObjectAttributes->ObjectName:pObjectAttributes->ObjectName:& 这个输出好像也不对, 你用GetLastError()可以得到错误代码,跟踪一下吗 |
|
|