SendDlgItemMessage(hX,IDC_FTPList,LB_ADDSTRING,0,(LPARAM)DirList); dError = NO_ERROR; do { if (!InternetFindNextFile (hDir, &pDirInfo)) { dError = GetLastError(); if ( dError == ERROR_NO_MORE_FILES ) { InternetCloseHandle(hDir); return 1; } else { ErrorOut (hX,GetLastError(), "InternetFindNextFile"); InternetCloseHandle(hDir); return 0; } } else { sprintf(DirList, pDirInfo.cFileName); if (pDirInfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) strcat(DirList," <DIR> "); SendDlgItemMessage(hX,IDC_FTPList,LB_ADDSTRING,0, (LPARAM)DirList); } } while ( TRUE); if (!InternetCloseHandle(hDir) ) { InternetCloseHandle(hDir); ErrorOut (hX,GetLastError(), "InternetCloseHandle error"); return 0; } else return 1;}int WINAPI Dumper(HWND hX, int intCtrlID, HINTERNET hResource) { LPSTR lpszData; // buffer for the data DWORD dwSize; // size of the data available DWORD dwDownloaded; // size of the downloaded data DWORD dwSizeSum=0; // size of the data in the textbox LPSTR lpszHolding; // buffer to merge the textbox data and buffer // Set the cursor to an hourglass. SetCursor(LoadCursor(NULL,IDC_WAIT)); // This loop handles reading the data. do { // The call to InternetQueryDataAvailable determines the amount // of data available to download. if (!InternetQueryDataAvailable(hResource,&dwSize,0,0)) { ErrorOut(hX,GetLastError(),"InternetReadFile"); SetCursor(LoadCursor(NULL,IDC_ARROW)); return FALSE; } else { // Allocate a buffer of the size returned by // InternetQueryDataAvailable. lpszData = new char[dwSize+1]; // Read the data from the HINTERNET handle. if(!InternetReadFile(hResource,(LPVOID)lpszData,dwSize,&dwDownloaded)) { ErrorOut(hX,GetLastError(),"InternetReadFile"); delete[] lpszData; break; } else { // Add a null terminator to the end of the data buffer. lpszData[dwDownloaded]='\0'; // Allocate the holding buffer. lpszHolding = new char[dwSizeSum + dwDownloaded + 1];
// Check if there has been any data written to the textbox. if (dwSizeSum != 0) { // Retrieve the data stored in the textbox if any. GetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding,dwSizeSum);
// Add a null terminator at the end of the textbox data. lpszHolding[dwSizeSum]='\0'; } else { // Make the holding buffer an empty string. lpszHolding[0]='\0'; } // Add the new data to the holding buffer strcat(lpszHolding,lpszData); // Write the holding buffer to the textbox. SetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding); // Delete the two buffers. delete[] lpszHolding; delete[] lpszData; // Add the size of the downloaded data to the textbox data size. dwSizeSum = dwSizeSum + dwDownloaded + 1; // Check the size of the remaining data. If it is zero, break. if (dwDownloaded == 0) break; } } } while(TRUE); // Close the HINTERNET handle. InternetCloseHandle(hResource); // Set the cursor back to an arrow. SetCursor(LoadCursor(NULL,IDC_ARROW)); // Return return TRUE; }
int WINAPI DisplayDir(HWND hX, DWORD dwFlags)
{
WIN32_FIND_DATA pDirInfo;
HINTERNET hDir;
DWORD dError;
char DirList[MAX_PATH];
DWORD dwTemp=MAX_PATH;
LPDWORD temp =&dwTemp;
LPVOID lpOption;
DWORD dwSize;
LPDWORD lpdwSize = &dwSize;SendDlgItemMessage(hX,IDC_FTPList,LB_RESETCONTENT,0,0);
if ( !(hDir = FtpFindFirstFile (hSecondary, TEXT ("*.*"), &pDirInfo,
dwFlags, 0) ))
if (GetLastError() == ERROR_NO_MORE_FILES)
{
MessageBox(hX,"There are no files here!!!","Display Dir",MB_OK);
InternetCloseHandle(hDir);
return 1;
}
else
{
ErrorOut (hX, GetLastError (), "FindFirst error: ");
InternetCloseHandle(hDir);
return 0;
} sprintf(DirList, pDirInfo.cFileName);
if (pDirInfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
strcat(DirList," <DIR> ");
SendDlgItemMessage(hX,IDC_FTPList,LB_ADDSTRING,0,(LPARAM)DirList); dError = NO_ERROR;
do
{
if (!InternetFindNextFile (hDir, &pDirInfo))
{
dError = GetLastError();
if ( dError == ERROR_NO_MORE_FILES )
{
InternetCloseHandle(hDir);
return 1;
}
else
{
ErrorOut (hX,GetLastError(), "InternetFindNextFile");
InternetCloseHandle(hDir);
return 0;
}
}
else
{
sprintf(DirList, pDirInfo.cFileName);
if (pDirInfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
strcat(DirList," <DIR> ");
SendDlgItemMessage(hX,IDC_FTPList,LB_ADDSTRING,0,
(LPARAM)DirList);
}
}
while ( TRUE); if (!InternetCloseHandle(hDir) )
{
InternetCloseHandle(hDir);
ErrorOut (hX,GetLastError(), "InternetCloseHandle error");
return 0;
}
else
return 1;}int WINAPI Dumper(HWND hX, int intCtrlID, HINTERNET hResource)
{
LPSTR lpszData; // buffer for the data
DWORD dwSize; // size of the data available
DWORD dwDownloaded; // size of the downloaded data
DWORD dwSizeSum=0; // size of the data in the textbox
LPSTR lpszHolding; // buffer to merge the textbox data and buffer // Set the cursor to an hourglass.
SetCursor(LoadCursor(NULL,IDC_WAIT)); // This loop handles reading the data.
do
{
// The call to InternetQueryDataAvailable determines the amount
// of data available to download.
if (!InternetQueryDataAvailable(hResource,&dwSize,0,0))
{
ErrorOut(hX,GetLastError(),"InternetReadFile");
SetCursor(LoadCursor(NULL,IDC_ARROW));
return FALSE;
}
else
{
// Allocate a buffer of the size returned by
// InternetQueryDataAvailable.
lpszData = new char[dwSize+1]; // Read the data from the HINTERNET handle.
if(!InternetReadFile(hResource,(LPVOID)lpszData,dwSize,&dwDownloaded))
{
ErrorOut(hX,GetLastError(),"InternetReadFile");
delete[] lpszData;
break;
}
else
{
// Add a null terminator to the end of the data buffer.
lpszData[dwDownloaded]='\0'; // Allocate the holding buffer.
lpszHolding = new char[dwSizeSum + dwDownloaded + 1];
// Check if there has been any data written to the textbox.
if (dwSizeSum != 0)
{
// Retrieve the data stored in the textbox if any.
GetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding,dwSizeSum);
// Add a null terminator at the end of the textbox data.
lpszHolding[dwSizeSum]='\0';
}
else
{
// Make the holding buffer an empty string.
lpszHolding[0]='\0';
} // Add the new data to the holding buffer
strcat(lpszHolding,lpszData); // Write the holding buffer to the textbox.
SetDlgItemText(hX,intCtrlID,(LPSTR)lpszHolding); // Delete the two buffers.
delete[] lpszHolding;
delete[] lpszData; // Add the size of the downloaded data to the textbox data size.
dwSizeSum = dwSizeSum + dwDownloaded + 1; // Check the size of the remaining data. If it is zero, break.
if (dwDownloaded == 0)
break;
}
}
}
while(TRUE); // Close the HINTERNET handle.
InternetCloseHandle(hResource); // Set the cursor back to an arrow.
SetCursor(LoadCursor(NULL,IDC_ARROW)); // Return
return TRUE;
}