URLDownloadToCacheFile problem - possible workarounds?
-
My program needs to download a file off the internet to get some information needed to continue. It does not need to save the information, just needs to read it once for the next step. I have tried
CString TempFile;
URLDownloadToCacheFile(NULL, _T("http://validurl/script.cfm?key=value"), TempFile.GetBufferSetLength(MAX_PATH), MAX_PATH, validcallback);Once those lines run, TempFile gets filled with a valid path to a temporary file, but the file doesn't actually exist - therefore I can't open it. The following code is what I'm using now, and it works. But I don't like it because it has a hard-coded temporary filename (therefore multiple instances may conflict).
CString TempFile;
TempFile.GetEnvironmentVariable(_(T"TEMP"));
TempFile.Appened(_T("\\MyProg.tmp"));
URLDownloadToFile(NULL, _T("sameurlasabove"), TempFile, validcallback);After those lines run, the file is created and contains the needed information. But again, it uses a hardcoded temp file, therefore multiple instances cannot run. So now for the questions: First of all, is URLDownloadToCacheFile failing because it's a text file generated by a script, and not a binary data file (like a jpg), therefore it doesn't cache it? Second, what is more practical in this situation. Would you implement code to generate a "random" temporary filename that's not in use? Or should I write code that can read the file right off the internet without saving it to disk first? I don't want to shoot a fly with a cannon, but I'm not sure which is the cannon.