简体   繁体   中英

Windows , WinInet C++ API

I am trying to use FTP to read some files from my local FTP filezilla server. However I struggle a bit, here is my code:

#include<Windows.h>
#include<WinInet.h>
#include<iostream>

using namespace std;


HINTERNET hOpener, hCon, hFinder;
Handle hFile;
char buffer[2000] = "\0";
WIN32_FIND_DATA findData;

hOpener = InternetOpen(TEXT("Chrome"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);

hCon = InternetConnect(hOpener, TEXT("127.0.0.1"), INTERNET_DEFAULT_FTP_PORT, TEXT("anonymous"), TEXT("adminn"), INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL);

hFinder = FtpFindFirstFile(hCon, NULL, &findData, INTERNET_FLAG_RELOAD, 0);

hFile = FtpOpenFile(hOpener, findData.cFileName, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);

LPDWORD x = 0;
cout << InternetReadFile(hFile, buffer, 280, x);

However, it prints 0 when it should print 1(basically there's a problem reading). What am I doing wrong here?

You are passing a NULL DWORD* pointer to the lpdwNumberOfBytesRead parameter of InternetReadFile() . You need to pass a pointer to a DWORD instead.

Change:

LPDWORD x = 0;
InternetReadFile(..., x);

to:

DWORD x = 0;
InternetReadFile(..., &x);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM