Hi, since I couldn't get the MFC stuff working in VC++ 2005 Express Edition, I decided to try using the WinInet API calls... I can get the name of the first FTP file by calling FtpFindFirstFile(), but after I call InternetFindNextFile() and do a few more lines of code my program gets "Unhandled exception at 0xbaadf00d in TestHarness.exe: 0xC0000005: Access violation reading location 0xbaadf00d."
Here is some of the relevent code:
What it's doing is skiping the while loop completely because InternetFindNextFile() fails and sets the LastError to 997 "Overlapped I/O operation is in progress."
Then when it gets to the cout line I get the exception (although it's not the cout that causes it. It's definitely a delayed side effect of the InternetFindNextFile() call).
What in the world is going on???
Here is some of the relevent code:
Code:
AutoCloseHandle hInet( InternetOpen( _T( "An FTP program" ),
INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL,
INTERNET_FLAG_ASYNC ) );
if ( hInet == NULL )
{
throw runtime_error( "InternetOpen() failed!" );
}
AutoCloseHandle hFtp( InternetConnect( hInet.Get(),
_T( "something.com" ),
INTERNET_DEFAULT_FTP_PORT,
NULL, NULL, // Default username & password.
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE,
NULL ) );
if ( hFtp == NULL )
{
throw runtime_error( "InternetConnect() failed!" );
}
// Now get a list of all the files in that directory.
vector<const string> foundFiles;
WIN32_FIND_DATA findData;
AutoCloseHandle hFindFile( FtpFindFirstFile( hFtp.Get(),
NULL,
&findData,
INTERNET_FLAG_RELOAD,
NULL ) );
if ( hFindFile != NULL )
{
const string file( WCharToString( findData.cFileName ) );
foundFiles.push_back( file );
while ( InternetFindNextFile( hFindFile.Get(), &findData ) != FALSE )
{
const string file( WCharToString( findData.cFileName ) );
foundFiles.push_back( file );
}
cout << endl << "Last Error was: " << ErrorString( GetLastError() ) << endl;
if ( GetLastError() != ERROR_NO_MORE_FILES )
{
throw runtime_error( "InternetFindNextFile() failed!" );
}
}
Then when it gets to the cout line I get the exception (although it's not the cout that causes it. It's definitely a delayed side effect of the InternetFindNextFile() call).
What in the world is going on???