我的动态分配的变量用 SecureZeroMemory 修整,然后 ReadFile 用一个短的 5char 字符串和一堆剩余的方块填充它。问题是字符串末尾的垃圾字符:
“电机驱动器”
ReadFile 的 lpNumberOfBytesRead 参数显示字符串是 10 个字符,可能是因为它是 Unicode?
有人可以帮我看看如何删除这些尾随的垃圾字符吗?是否有像 ZeroMemory 这样的功能可以清除它们?
TCHAR *sIncoming;
sIncoming = (TCHAR *) malloc(sizeof(TCHAR) * 4096 + sizeof(TCHAR));
RtlZeroMemory(sIncoming ,sizeof(sIncoming));
// (a string array with no characters in it: "")
bSuccess = ReadFile(hPipe,sIncoming ,BUFSIZE*sizeof(TCHAR),&dwBytesRead,NULL);
// Now the string array has the incoming string plus extra characters in it:
// "motor췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍"
free(sIncoming);
谢谢!