Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "comm.h"
- HRESULT COMM_URLDownloadToFile(char *inURL, char *inFILE)
- {
- HRESULT returnVal;
- HMODULE library = LoadLibraryA("urlmon.dll");
- _COMM_URLDownloadToFileA function;
- function = (_COMM_URLDownloadToFileA)GetProcAddress(library, "URLDownloadToFileA");
- returnVal = function(0, inURL, inFILE, 0, 0);
- FreeLibrary(library);
- free(function);
- return returnVal;
- }
- DWORD COMM_URLDownloadToTempFile(char *inURL)
- {
- HRESULT returnVal = NULL;
- char *tempname;
- tempname = tmpnam(0);
- returnVal = COMM_URLDownloadToFile(inURL, tempname);
- if (returnVal == S_OK)
- {
- remove(tempname);
- return COMM_OK;
- }
- return COMM_GENERR;
- }
- DWORD COMM_URlDownloadToString(char *inURL, char *outBUFF, BOOL binary)
- {
- HRESULT returnVal = NULL;
- FILE *tempFile;
- char *fbuffer;
- long fsize;
- size_t fresult;
- char *tempname;
- tempname = tmpnam(0);
- returnVal = COMM_URLDownloadToFile(inURL, tempname);
- if (returnVal == S_OK)
- {
- if (binary) {
- tempFile = fopen(tempname, "rb");
- } else {
- tempFile = fopen(tempname, "r");
- }
- if (tempFile == NULL) { return COMM_FILEERR; }
- fseek(tempFile, 0, SEEK_END);
- fsize = ftell(tempFile);
- rewind(tempFile);
- fbuffer = (char*)malloc(fsize*sizeof(char));
- if (fbuffer == NULL) { return COMM_MEMERR; }
- fresult = fread(fbuffer, 1, fsize, tempFile);
- if (fresult != fsize) { return COMM_READERR; }
- fclose(tempFile);
- free(fbuffer);
- }
- strcpy(outBUFF, fbuffer);
- return COMM_OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement