Click here to Skip to main content
11,797,355 members (75,037 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ Win32 MinGW
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.

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\"\nPort = \"%d\"\nUsername = \"%s\"\nPassword = \"%s\"", server, port, username, password );

	// Open Internet Connection
	if( NULL != progress )
		progress( id, ATCFTP_STATUS_PREPARING, 0, 0 );
		#ifdef SHOW_ERRORS
		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)) )
		#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 );
		return false;
	return true;
Posted 5-Sep-11 9:35am
cariolihome at 5-Sep-11 17:18pm
I tried Your code and it works without any call to InternetGetLastResponseInfo function.
May be atcftp_put function parameters are wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 475
1 Maciej Los 370
2 OriginalGriff 363
3 Abhinav S 344
4 Andy Lanng 296
0 OriginalGriff 2,092
1 Maciej Los 1,760
2 KrunalRohit 1,436
3 CPallini 1,245
4 ppolymorphe 893

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 5 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100