FindFirstFile 返回句柄无效
#include "stdafx.h"
#include "iostream"
#include "windows.h"
#define MAX_PATH 300
using namespace std;
void MyFindFile1(LPCTSTR lpPath);
int _tmain(int argc, _TCHAR* argv[])
{
const char *str = "D:\\test";
LPCTSTR lpPath = (LPCTSTR)str;
MyFindFile1(lpPath);
system("Pause");
return 0;
}
void MyFindFile1(LPCTSTR lpPath)
{
TCHAR MFind[MAX_PATH] = {_T("\0")};
WIN32_FIND_DATA findFileDate ;
bool bRet;
_tcscpy_s(MFind,MAX_PATH,lpPath);
_tcscat_s(MFind,_T("\\*.*"));
printf("%\s\n",MFind);
HANDLE hFind = ::FindFirstFile(MFind, &findFileDate);
if(INVALID_HANDLE_VALUE == hFind)
{
printf("无效句柄!\n");
return;
}
else
{
printf("句柄有效\n");
}
}
始终是输出无效句柄,我已经在D:\\test中建立了一些文件和文件夹。