使用UNICODE_STRING 時(shí),一定要手動(dòng)設(shè)置UNICODE_STRING 的Length和MaximumLength 成員,不要想當(dāng)然的認(rèn)為設(shè)置了Buffer后,Length和MaximumLength 成員就會(huì)根據(jù)Buffer被自動(dòng)設(shè)置。由其是當(dāng)自己寫(xiě)的函數(shù)用UNICODE_STRING作為參數(shù)返回時(shí),一定要設(shè)置Length和 MaximumLength 成員,不然很可能得到非預(yù)期結(jié)果。
// 測(cè)試
UNICODE_STRING usTest;
RtlInitUnicodeString(&usTest, NULL);
usTest.MaximumLength = 16;
usTest.Buffer = L"Hello";
usTest.Length = (USHORT)wcslen(usTest.Buffer);
TRACE_MSG(TL_NORMAL, "len:%d,maxlen:%d,buffer:%ws", usTest.Length, usTest.MaximumLength, usTest.Buffer);
posted on 2011-08-22 10:16
水 閱讀(686)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
windows驅(qū)動(dòng)