by Valentin K » Mon, 14 Mar 2005 02:33:16
'am working on a very little FTP client and since the beginning, I have a
very strange bug that crashes my application. The bug produces when I would
like to display a directory. But not the first time and only if a automatic
variable is used before the second call.
I made several checks and tests:
- Insulate the application into a Console Application with the
minimum necessary : always the same error (under WinXP with the last version
of LCC)
- Compile under DevC++ : It Works! (under WinXP)
- Compile under an older version of LCC on Windows98 : It Works!
- Compile with these same version under WinXP : Error
- Execute the program compiled under Win98 on WinXP : it Works!!
My diagnostic is :
There is a bug, apparently not in my code, which make an error on the
application stack. Where could be the error???
Thank you very much for your help.
Valentin KIELBASA
Here below the source and you can found the full project at this address:
http://www.phidus.net/ftpbug/testFTP.zip
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ftp.h"
int main(void)
{
HINTERNET g_ftphdl;
char buffer[512];
g_ftphdl = FTP_CreateSession("ftp.free.fr", "anonymous", "",
21);
if(g_ftphdl == 0)
{
printf("\nERREUR : Impossible de se connecter ?
l'he");
return 1;
}
FTP_DisplayDir(g_ftphdl, INTERNET_FLAG_RELOAD, 0);
while(1)
{
printf("\n> change directory for : ");
fgets(buffer, sizeof(buffer)-1, stdin);
FTP_ChangeDir(g_ftphdl, buffer);
FTP_DisplayDir(g_ftphdl, INTERNET_FLAG_RELOAD, 0);
}
return 0;
}
/*------------------------------------------------------------------------
Procedure: createFtpSession ID:1
Purpose: Cr une session FTP
Input: serveur
user
password
port : Si = 0, port par daut cad
INTERNET_DEFAULT_FTP_PORT
Output: Structure de type HINTERNET
Errors:
------------------------------------------------------------------------*/
HINTERNET FTP_CreateSession(char *serveur, char *user, char *pass, int port)
{
/********************************************************
* Dlaration de variables
********************************************************/
HINTERNET hOpenHandle, hConnectHandle;
/********************************************************
* Code
********************************************************/
if(port == 0) port = INTERNET_DEFAULT_FTP_PORT;
hOpenHandle = InternetOpen("FTPManager",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
hConnectHandle = InternetConnect(hOpenHandle, serveur,
port, user,
pass, INTERNET_SERVICE_FTP,0,0);
return hConnectHandle;
}
/*------------------------------------------------------------------------
Procedure: Displ