Win10下_findnext()调试时中断

系统重装升级到win10之后,在win7下面可以运行的文件夹遍历代码会中断。

 ***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****

0x00007FFEC8614ECD (ntdll.dll) (demo.exe 中)处的第一机会异常:  0xC0000005:  写入位置 0x00000000036E0590 时发生访问冲突。
0x00007FFEC8614ECD (ntdll.dll) (demo.exe 中)处有未经处理的异常:  0xC0000005:  写入位置 0x00000000036E0590 时发生访问冲突。

原因:
因为_findnext()返回类型为intptr_t而非long型,从“intptr_t”转换到“long”丢失了数据。

vector<string> BrowseFilenamesOneLayer(const char* dir, const char *filespec)
        {

            _chdir(dir);
            _finddata_t fileInfo;
            //long lfDir=0;
            intptr_t  lfDir;
            vector<string> fileVec;
            fileVec.clear();

            if ((lfDir = _findfirst(filespec, &fileInfo)) == -1)
                cout << "No file is found" << endl;
            else
            {
                do
                {
                    char filename[_MAX_PATH];
                    strcpy_s(filename, dir);
                    strcat_s(filename, "//");
                    strcat_s(filename, fileInfo.name);

                    fileVec.push_back(filename);
                    cout << "name=" << filename << endl;
                } while (_findnext(lfDir, &fileInfo) == 0);
            }
            _findclose(lfDir);

            return fileVec;
        }
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值