Reputation: 553
I've been researching this for hours. I am VERY new to C++, and don't understand any solutions I have found thus far.
I'm trying to make a cURL file downloader in my form application, but I get this darn error:
Error 50 error C3374: can't take address of 'EmperorAntiVirusInstaller::FileDownloader::write_data' unless creating delegate instance c:\users\bailey\documents\visual studio 2010\projects\emperor antivirus installer\emperor antivirus installer\FileDownloader.h 97
The code is as below:
private:
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
System::Void beginDownload(void) {
CURL *curl;
FILE *fp;
CURLcode res;
char *url = "http://localhost/aaa.txt";
char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
curl = curl_easy_init();
if(curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &FileDownloader::write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
}
Additionally, the form's name is FileDownloader.
The erroring line is:
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &FileDownloader::write_data);
I'm looking to find a nicely explained & simple answer on how to resolve this issue. :/
Upvotes: 0
Views: 621
Reputation: 490108
You're trying to pass a pointer to a member function. It needs a pointer to a non-member function. You need to write a function that does what you need, but not as a member of a class.
At least if memory serves, if you just want the data written to the file you specify in your call with CURLOPT_WRITEDATA
, you don't need to use CURLOPT_WRITEFUNCTION
at all -- the default function will just write the data to the file you pass.
I suppose I should also mention, however, that (based on the mention of a delegate instance in the error message) you seem to be using C++/CLI instead of real C++. If that's the case, nearly everything else is probably open to at least a little question -- C++/CLI is quite a bit like C++ in some ways, but just enough different others to cause problems on a semi-regular basis.
Upvotes: 1