gpt4 book ai didi

c - 我无法使用 SHFileOperation 删除文件

转载 作者:可可西里 更新时间:2023-11-01 10:38:39 25 4
gpt4 key购买 nike

我想删除一个文件到回收站。我使用这段代码。

    SHFILEOPSTRUCT FileOp;
FileOp.hwnd = NULL;
FileOp.wFunc=FO_DELETE;
FileOp.pFrom= lpFileName; //it's my value \\?\C:\WorkFolder\qweqw.docx
FileOp.pTo = NULL;
FileOp.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
FileOp.hNameMappings=NULL;
int t_res = SHFileOperation(&FileOp); // t_res = 124
return t_res;

我做错了什么?提前致谢。

最佳答案

  1. 什么是t_res,应该给出错误代码并提示原因
  2. 注意 pFrom 接受文件,而不是单个文件,所以你应该用两个零终止缓冲区,参见 doc excerpt from MSDN :

Although this member is declared as a single null-terminated string, it is actually a buffer that can hold multiple null-delimited file names. Each file name is terminated by a single NULL character. The last file name is terminated with a double NULL character ("\0\0") to indicate the end of the buffer.

关于c - 我无法使用 SHFileOperation 删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11225667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com