gpt4 book ai didi

c++ - 错误 124 - SHFileOperation 的系统调用级别不正确

转载 作者:行者123 更新时间:2023-11-28 00:11:42 25 4
gpt4 key购买 nike

我正在尝试使用 SHFileOperation 将文件/目录从一个位置复制到另一个位置。到目前为止,我的代码是,

    for(int index=0; index < clbSource.GetCount();index++ )
{
SHFILEOPSTRUCT SHFileOp;
CString src,dest;
std::string NULLTermination="\\0\\0";

//Get source file/directory path from CListBox
int n = clbSource.GetTextLen(index);
clbSource.GetText(index, src.GetBuffer(n));
src.ReleaseBuffer();
CT2CA pszConvertedAnsiString (src);
std::string strStdS (pszConvertedAnsiString);

//replace single slash with double
size_t found = 0, next = 0;
while( (found = strStdS.find('\\', next)) != std::string::npos )
{
strStdS.insert(found, "\\");
next = found+4;
}

//Add double null termination
strStdS.append(NULLTermination);
std::wstring stempS = s2ws(strStdS);

//Get source file/directory path from CListBox
int m = clbDest.GetTextLen(index);
clbDest.GetText(index, dest.GetBuffer(n));
dest.ReleaseBuffer();
CT2CA pszConvertedAnsiStringd (dest);
std::string strStdD (pszConvertedAnsiStringd);

//replace single slash with double
size_t foundD = 0, nextD = 0;
while( (foundD = strStdD.find('\\', nextD)) != std::string::npos )
{
strStdD.insert(foundD, "\\");
nextD = foundD+4;
}

//Add double null termination
strStdD.append(NULLTermination);
std::wstring stempD = s2ws(strStdD);


// set up File Operation structure
ZeroMemory(&SHFileOp, sizeof(SHFILEOPSTRUCT));

// application the owner of the progress dialog.
SHFileOp.hwnd = GetSafeHwnd();
SHFileOp.wFunc = FO_COPY;

SHFileOp.pFrom = stempS.c_str();
//SHFileOp.pFrom = _T("E:\\backup\\java softwares\0\0");

SHFileOp.pTo = stempD.c_str();
//SHFileOp.pTo = _T("E:\\Tmp\0\0");

// Set the flags.
SHFileOp.fFlags = FOF_SIMPLEPROGRESS;

// Do it.
DWORD result = SHFileOperation(&SHFileOp);

//Check for success
if(result!=0)
{
::AfxMessageBox(ERR_MSG_FAILED_TO_COPY);
}
else
::AfxMessageBox(SUCCESS);

}

现在,结果是非零的,即 124。也通过此链接 System Error 124 - ERROR_INVALID_LEVEL with SHFileOperation .无法理解问题出在哪里。

注意:如果将硬编码值(如图所示)传递给“SHFileOp.pFrom”和“SHFileOp.pTo”,它可以正常工作。

有人能帮忙吗??

最佳答案

由于“历史原因”,

SHFileOperation 不返回标准的 Windows 错误代码。

MSDN:SHFileOperation , 在“返回值”下有一个可能的结果列表。

124 == 0x7C == The path in the source or destination or both was invalid.

检查您在结构中实际传递的值,路径转换中可能存在错误。

关于c++ - 错误 124 - SHFileOperation 的系统调用级别不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32738935/

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