这是令人困惑的我...我写一个DLL提供FTP上传和下载功能。我使用的Windows核能API的实现这一目标,当我打个电话给InternetConnect()失败,错误代码6(无效的句柄值)。我试图找出它为什么一直没有,所以我添加了一个InternetGetLastResponseInfo()调用,它奇迹般地开始工作。我注释掉调用和它停止工作。我反复几次。不要紧,我把通话InternetGetLastResponseInfo()要么,只要该函数在某些点称为,它的工作原理。如果我注释掉的调用,然后InternetConnect()调用失败。
ATCFTP_EXTERN bool atcftp_put(
char *server,
int port,
char *username,
char *password,
char *localfile,
char *remotefile,
ATCFTP_CALLBACK progress,
int id )
{
HINTERNET hInet, hFTP, hFile;
FILE *pFile;
long total;
long left;
char *buffer;
#ifdef DEBUG
buffer = (char*) malloc( 512 );
memset( buffer, 0, 512 );
sprintf( buffer, "Server = \"%s\"\nPort = \"%d\"\nUsername = \"%s\"\nPassword = \"%s\"", server, port, username, password );
MessageBox( NULL, buffer, "ATCFTP DEBUG", MB_OK | MB_ICONINFORMATION );
#endif
// Open Internet Connection
if( NULL != progress )
progress( id, ATCFTP_STATUS_PREPARING, 0, 0 );
if( NULL == (hInet=InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG , NULL, NULL, 0)) )
{
#ifdef SHOW_ERRORS
ShowError( "InternetOpen");
#endif
return false;
}
// Connect to FTP server
if( NULL != progress )
progress( id, ATCFTP_STATUS_CONNECTING, 0, 0 );
if( NULL == (hFTP=InternetConnect(hInet,server,port,username,password,INTERNET_SERVICE_FTP,0,0)) )
{
#ifdef SHOW_ERRORS
ShowError( "InternetConnect" );
DWORD dwError;
char lpszBuffer[512];
DWORD dwBufferLength = sizeof(lpszBuffer);
InternetGetLastResponseInfo( &dwError, lpszBuffer, &dwBufferLength );
MessageBox( NULL, lpszBuffer, "ATCFTP ERROR", MB_OK | MB_ICONERROR );
#endif
InternetCloseHandle(hInet);
return false;
}
return true;
}