tycoon
驱动牛犊
驱动牛犊
  • 注册日期2007-07-25
  • 最后登录2008-02-26
  • 粉丝0
  • 关注0
  • 积分330分
  • 威望34点
  • 贡献值0点
  • 好评度33点
  • 原创分0分
  • 专家分0分
阅读:1940回复:7

简单问题,把盘符和文件名连到一起,为何出错了,高人指点一下吧??

楼主#
更多 发布于:2007-07-25 10:20
简单问题,把盘符和文件名连到一起,连接后的结果不正确,前面的盘符和冒号没有了,不知为何?
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);
tooflat
论坛版主
论坛版主
  • 注册日期2002-07-08
  • 最后登录2014-03-11
  • 粉丝2
  • 关注0
  • 积分1007分
  • 威望551点
  • 贡献值3点
  • 好评度476点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2007-07-25 12:47
在调用RtlAppendUnicodeStringToString之前先正确设置FullName.Length
tycoon
驱动牛犊
驱动牛犊
  • 注册日期2007-07-25
  • 最后登录2008-02-26
  • 粉丝0
  • 关注0
  • 积分330分
  • 威望34点
  • 贡献值0点
  • 好评度33点
  • 原创分0分
  • 专家分0分
板凳#
发布于: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方法把路径转换为大写字母后,最后一个字母是乱码??
linuxyf
驱动小牛
驱动小牛
  • 注册日期2007-04-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望162点
  • 贡献值0点
  • 好评度161点
  • 原创分1分
  • 专家分0分
地板#
发布于: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或许更简洁一些。
在孤独和无助中缓慢前行...
znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
地下室#
发布于:2007-07-25 17:46
unicodestring的buffer没有空字符结尾,它是以长度确定字符串的.

你需要考虑这个问题
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
linuxyf
驱动小牛
驱动小牛
  • 注册日期2007-04-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望162点
  • 贡献值0点
  • 好评度161点
  • 原创分1分
  • 专家分0分
5楼#
发布于:2007-07-26 08:25
znsoft大哥讲的好啊,一语中的。
在孤独和无助中缓慢前行...
tycoon
驱动牛犊
驱动牛犊
  • 注册日期2007-07-25
  • 最后登录2008-02-26
  • 粉丝0
  • 关注0
  • 积分330分
  • 威望34点
  • 贡献值0点
  • 好评度33点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2007-07-26 11:32
感谢版主、网管和linuxyf,问题解决了。
sunway_yin
驱动牛犊
驱动牛犊
  • 注册日期2006-06-09
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分312分
  • 威望42点
  • 贡献值0点
  • 好评度31点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2007-07-26 15:18
能告诉我你是怎样获取到盘符的么 ? 特别是在irp_mj_read 里面 (2000系统)。
我的油箱是sunway_yin@sina.com 如能回答万分感激啊:)
游客

返回顶部