我向客户提供了一个使用 Visual C++ 开发的应用程序,该应用程序在我的环境中运行良好。_tfopen不幸的是,我的客户在调用时收到错误 22 。
这是一个与我在此应用程序中编写的代码类似的小片段:
#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <wchar.h>
#include "tchar.h"
FILE* fp;
int openFile(const TCHAR* p, const TCHAR* r)
{
errno_t err = 0;
fp = _tfopen(p, r);
if (!fp)
{
err = errno;
_tprintf(_T("Error %d, can't open file: %s with rights %s"), err, p, r);
}
else
{
printf("All is ok\n");
}
return err;
}
int main()
{
openFile(_T("\\\\127.0.0.1\\hidden_folder$\\folder\\video_file.mxf"), _T("rb"));
return 0;
}
我的客户得到:
Error 22, can't open file: \\127.0.0.1\hidden_folder$\folder\video_file.mxf with rights rb
错误 22 表示EINVAL参数无效。但是,就我而言,论点是正确的(根据日志)。
这种行为的原因是什么?
我尝试了很多东西来重现这个错误:删除video_file.mxf,更改文件的位置,更改文件的权限,......没关系,我从来没有得到错误22。
笔记:
- 我知道
_tfopen现在已弃用,我还创建了一个使用的版本_tfopen_s,问题仍然存在。 - 这不是这个问题的重复,因为就我而言,我没有错误并且我想重现它(以了解如何更正它)。