阅读:1941回复:7
简单问题,把盘符和文件名连到一起,为何出错了,高人指点一下吧??
简单问题,把盘符和文件名连到一起,连接后的结果不正确,前面的盘符和冒号没有了,不知为何?
UNICODE_STRING FullName; UNICODE_STRING UFullName; WCHAR TEMP[512]; RtlInitEmptyUnicodeString(&FullName, TEMP, sizeof(TEMP)); FullName.Buffer[0] = DevExt->DriveLetter; FullName.Buffer[1] = L':'; FullName.Buffer[2] = L'\0'; RtlAppendUnicodeStringToString(&FullName, &FileObject->FileName); RtlUpcaseUnicodeString(&UFullName, &FullName, TRUE); KdPrint(("*********************************************************")); KdPrint(("The driver is \"%wc\"", DevExt->DriveLetter)); KdPrint(("The fileName is \"%ws\"", FileObject->FileName.Buffer)); KdPrint(("The fullpath is \"%ws\"", FullName.Buffer)); KdPrint(("The fullpath is \"%ws\"", UFullName.Buffer)); KdPrint(("*********************************************************")); RtlFreeUnicodeString(&FullName); RtlFreeUnicodeString(&UFullName); |
|
沙发#
发布于:2007-07-25 12:47
在调用RtlAppendUnicodeStringToString之前先正确设置FullName.Length
|
|
板凳#
发布于:2007-07-25 14:57
tooflat版主,我按如下代码做法:
RtlInitEmptyUnicodeString(&FullName, TEMP, FileObject->FileName.Length + 2); FullName.Length = 0; FullName.Buffer[0] = DevExt->DriveLetter; FullName.Buffer[1] = L':'; for ( u = 2; u < FileObject->FileName.Length + 2; u++) { FullName.Buffer = FileObject->FileName.Buffer[u - 2]; } FullName.Length = FileObject->FileName.Length + 2; RtlUpcaseUnicodeString(&UFullName, &FullName, TRUE); KdPrint(("****************************Read*****************************")); KdPrint(("The driver is \"%wc\"", DevExt->DriveLetter)); KdPrint(("The fileName is \"%ws\"", FileObject->FileName.Buffer)); KdPrint(("The fullpath is \"%ws\"", FullName.Buffer)); KdPrint(("The fullpath is \"%ws\"", UFullName.Buffer)); KdPrint(("****************************Read*****************************")); 打印结果是: 00000008 1.08714151 ****************************Read***************************** 00000009 1.08714855 The driver is "D" 00000010 1.08715546 The fileName is "\OriginalKeyHNS.xml" 00000011 1.08716166 The fullpath is "D:\OriginalKeyHNS.xml" 00000012 1.08716810 The fullpath is "D:\ORIGINALKEYHNS.XM?" 00000013 1.08717370 ****************************Read***************************** 00000014 1.08778095 sfilter!SfIsObjectFile: fcb->NodeTypeCode = 705 00000015 1.08779669 sfilter!SfCreate: FileName = D:\OriginalKeyHNS.xml 00000016 1.08799303 sfilter!SfCreate: IsEncryptFlagExist = 0, IsNeedEncrypt = 0, NewElement = 0 00000017 1.08808017 ****************************Read***************************** 00000018 1.08808720 The driver is "D" 00000019 1.08809388 The fileName is "\OriginalKeyHNS.xml" 00000020 1.08810008 The fullpath is "D:\OriginalKeyHNS.xml" 00000021 1.08810639 The fullpath is "D:\ORIGINALKEYHNS.XM?" 00000022 1.08811200 ****************************Read***************************** 00000023 35.05121613 sfilter!SfIsObjectFile: fcb->NodeTypeCode = 705 00000024 35.05124283 sfilter!SfCreate: FileName = D:\qq.txt 00000025 35.05144119 sfilter!SfCreate: IsEncryptFlagExist = 0, IsNeedEncrypt = 0, NewElement = 1 00000026 35.05153275 ****************************Read***************************** 00000027 35.05154037 The driver is "D" 00000028 35.05154419 The fileName is "\qq.txt" 00000029 35.05154800 The fullpath is "D:\qq.txt" 00000030 35.05155563 The fullpath is "D:\QQ.TX[" 00000031 35.05155945 ****************************Read***************************** 为何使用RtlUpcaseUnicodeString方法把路径转换为大写字母后,最后一个字母是乱码?? |
|
地板#
发布于:2007-07-25 16:42
楼主可以这样试一下:
RtlInitEmptyUnicodeString(&FullName, TEMP, FileObject->FileName.Length + 2); FullName.Length = 0; FullName.Buffer[0] = DevExt->DriveLetter; FullName.Buffer[1] = L':'; for ( u = 2; u < FileObject->FileName.Length + 2; u++) { FullName.Buffer = FileObject->FileName.Buffer[u - 2]; } FullName.Length = FileObject->FileName.Length + 2; //RtlUpcaseUnicodeString(&UFullName, &FullName, TRUE); for (m = 0; m < FileObject->FileName.Length + 2; m++) { FullName.Buffer[m] = towupper(FullName.Buffer[m]); } KdPrint(("****************************Read*****************************")); KdPrint(("The driver is \"%wc\"", DevExt->DriveLetter)); KdPrint(("The fileName is \"%ws\"", FileObject->FileName.Buffer)); KdPrint(("The fullpath is \"%ws\"", FullName.Buffer)); KdPrint(("The fullpath is \"%ws\"", UFullName.Buffer)); KdPrint(("****************************Read*****************************")); 其实在看tooflat版主的程序中,不止一个地方要把小写字母转化成大写字母,用到的方法都是: *Name - L'a' + L'A'; 其实用这个内置的方法towupper或许更简洁一些。 |
|
|
地下室#
发布于:2007-07-25 17:46
unicodestring的buffer没有空字符结尾,它是以长度确定字符串的.
你需要考虑这个问题 |
|
|
5楼#
发布于:2007-07-26 08:25
znsoft大哥讲的好啊,一语中的。
|
|
|
6楼#
发布于:2007-07-26 11:32
感谢版主、网管和linuxyf,问题解决了。
|
|
7楼#
发布于:2007-07-26 15:18
能告诉我你是怎样获取到盘符的么 ? 特别是在irp_mj_read 里面 (2000系统)。
我的油箱是sunway_yin@sina.com 如能回答万分感激啊:) |
|