[捉蟲記錄] access violation writing location _findnext

LinJM-機器視覺發表於2015-08-28

jeremy lin

在Windows 10中VS2013下執行如下程式:

void getFiles(string path, vector<string>& files)
{
	long hFile = 0;

	// _finddata_t ÊÇÓÃÀ´´æ´¢Îļþ¸÷ÖÖÐÅÏ¢µÄ½á¹¹Ìå
	struct _finddata_t fileinfo;
	string p;

	// 
	if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
	{
		do
		{
			if ((fileinfo.attrib &  _A_SUBDIR))
			{
				if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
				{
					files.push_back(p.assign(path).append("\\").append(fileinfo.name));
					getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
				}
			}
			else
			{
				files.push_back(p.assign(path).append("\\").append(fileinfo.name));
			}

		} while (_findnext(hFile, &fileinfo) == 0);

		_findclose(hFile);
	}

}

void getFilesFormat(string path, vector<string>& files, string format)
{

	//long   hFile = 0;
	intptr_t hFile = 0;
	struct _finddata_t fileinfo;
	string p;
	if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1)
	{
		do
		{
			if ((fileinfo.attrib &  _A_SUBDIR))
			{
				if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
				{
					getFilesFormat(p.assign(path).append("\\").append(fileinfo.name), files, format);
				}
			}
			else
			{
				files.push_back(p.assign(path).append("\\").append(fileinfo.name));
			}
		} while (_findnext(hFile, &fileinfo) == 0);

		_findclose(hFile);
	}
}

報如下錯誤:

access violation writing location



note:在win10 vs2015情況下執行程式未報錯。


解決方案:

把long hFile改成 intptr_t hFile


相關文章