Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID


We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

InternetConnect fails unless I reference InternetGetLastResponseInfo

This is perplexing me... I am writing a DLL to provide FTP upload and download functionality. I am using the Windows INET API's to achieve this, and when I make a call to InternetConnect() it fails with error code 6 (Invalid Handle Value). I was trying to figure out why it kept failing, so I added a call to InternetGetLastResponseInfo() and it magically started working. I commented out the call and it stopped working. I repeated this several times. It doesn't matter where I put the call to InternetGetLastResponseInfo() either, as long as the function is called at some point, it works. If I comment out the call, then the call to InternetConnect() fails.

[code]ATCFTP_EXTERN bool atcftp_put(
char *server,
int port,
char *username,
char *password,
char *localfile,
char *remotefile,
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"
Port = "%d"
Username = "%s"
Password = "%s"", server, port, username, password );

// Open Internet Connection
if( NULL != progress )
progress( id, ATCFTP_STATUS_PREPARING, 0, 0 );
ShowError( "InternetOpen");
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)) )
ShowError( "InternetConnect" );
DWORD dwError;
char lpszBuffer[512];
DWORD dwBufferLength = sizeof(lpszBuffer);
InternetGetLastResponseInfo( &dwError, lpszBuffer, &dwBufferLength );
MessageBox( NULL, lpszBuffer, "ATCFTP ERROR", MB_OK | MB_ICONERROR );
return false;

return true;

Sign In or Register to comment.