I have tried URLDownloadToFile() function but i dont have urlmon.h and urlmon.lib in my library and in my system also i dont have urlmon.dll file :\
Anyway i downloaded urlmon.dll file and tried to get address of URLDownloadToFile function by using GetProcAddress and LoadLibrary functions. Its working now but its not portable.
I also found a code in internet and i tried it but doesnt work . This is my code with URLDownloadToFile api.
#include <windows.h>
#include <stdio.h>
HRESULT (*_URLDownloadToFile)(
LPUNKNOWN pCaller,
LPCTSTR szURL,
LPCTSTR szFileName,
DWORD dwReserved,
void* lpfnCB
);
int main(){
_URLDownloadToFile = GetProcAddress(LoadLibrary("urlmon.dll"),"URLDownloadToFileA");
printf("%X",_URLDownloadToFile);
_URLDownloadToFile( NULL,"http://www.lib.berkeley.edu/TeachingLib/Guides/Internet/limiting.pdf",
"C:\\asd.pdf", 0, NULL);
getchar();
return 0;
}
This code i found on internet.
#include <windows.h>
#include <wininet.h>
typedef PVOID HINTERNET ;
typedef HINTERNET (WINAPI *InetOpenA)(LPCTSTR , char* ,char*,char* ,char* ); //InterNetOpenA
typedef HINTERNET (WINAPI *InetOpenUrlA) (HINTERNET, LPCSTR, char* ,char* ,char* ,char* ); //InternetOpenUrlA
typedef BOOL (WINAPI *InetReadFile) (HINTERNET, LPVOID , DWORD , LPDWORD); //InternetReadFileA
typedef HANDLE (WINAPI *CreatFile) (LPCTSTR,int,int,int,int,int,int); //CreateFileA
typedef BOOL (WINAPI *WritFile) (HANDLE,LPCVOID,int,LPDWORD,int); //WriteFileA
BOOL D_File(char* FromHere)
{
HINTERNET InternetHandle;
HINTERNET UrlHandle;
HANDLE FileHandle;
unsigned long BytesNext = 1;
unsigned long BytesWritten = 0;
char Buffer[2048];
char *SaveFile = "D:\\File.pdf"; //File Destination
// Opening page, with File Save Destination
InternetHandle = InternetOpen(SaveFile, 0, 0, 0, 0);
if(InternetHandle != 0)
{
UrlHandle = InternetOpenUrl(InternetHandle, FromHere, 0, 0, 0, 0); //Connectin to your File
FileHandle = CreateFile(SaveFile, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0); //Creating File to spec. Destination, with File Attributes.
while(BytesNext != 0)
{
InternetReadFile(UrlHandle, Buffer, sizeof(Buffer), &BytesNext);
WriteFile(FileHandle, Buffer, BytesNext, &BytesWritten, 0); //Writing bytes to File
}
CloseHandle(FileHandle);
CloseHandle(UrlHandle);
CloseHandle(InternetHandle);
}
return FALSE;
}
int main() {
D_File("http://www.lib.berkeley.edu/TeachingLib/Guides/Internet/limiting.pdf"); //Your URL Here
return 0;
}
I know socket programming, i can download any web page by using Get methot etc. But i want to download anyfile from internet also by using only winsock library. Can i do that? is there any way?


Sign In
Create Account


Back to top









