is there a way to initiate a download? like make the download window pop up? I know I could open an IE window to the file but I want to be able to save it to a location...so how could I do that?
Printable View
is there a way to initiate a download? like make the download window pop up? I know I could open an IE window to the file but I want to be able to save it to a location...so how could I do that?
You could create your own download window...
I think it's URLDownloadToFile or something similar.
Call LoadLibrary -- use shdocvw.dll. Call is: DoFileDownload.
long DoFileDownload(LPCSTR url);
MSDN doesn't document this call, but it's part of IE 5 & 6. It brings up the cute dialog boxes.
So you'd have to do:
PHP Code:typedef long (WINAPI* L_CASTR)(LPCSTR);
HMODULE hMyDll = LoadLibrary(TEXT("shdocvw.dll"));
if(hMyDll == NULL) {} // error
L_CASTR pDoFileDownload = (L_CASTR)GetProcAddress(hMyDll, TEXT("DoFileDownload")); // DoFileDownloadA?
// call
pDoFileDownload("http://www....");
Parksie...URLDownloadToFile gets the html not the file
okay I tried the code cornedbee gave...but a messagebox popped up giving a wierd error (I don't have any message boxes in my program...its not my custom error)
http://www.vbforums.com/attachment.php?s=&postid=718756
as a test Im downloading this file: http://www.terminalstudio.com/files/instlawnm.exe
(first one i saw on download.com ;) )
It has to be unicode text. My protoype is wrong.
Sorry.
So you want LPCWSTR (or for the non-masochists, const wchar_t*).
so
? :confused: 5 errors :(Code:ypedef long (WINAPI* L_CASTR)(LPCSTR(const wchar_t*));
HMODULE hMyDll = LoadLibrary(TEXT("shdocvw.dll"));
if(hMyDll == NULL) {} // error
L_CASTR pDoFileDownload = (L_CASTR)GetProcAddress(hMyDll, TEXT("DoFileDownload")); // DoFileDownloadA?
// call
pDoFileDownload("http://wwwterminalstudio.com/files/instlawnn.exe");
URLDownloadToFile() certainly downloads files. It gets raw data from the server, and saves it to a file. Ive used it before to download files.
Z.
Oh im such an idiot! It gets the html of a web page...but if you go to an exe, it gets the info on the exe :rolleyes: When I was using that before I couldn't figure out how to get the % done....can you show me? (msdn's example confused the hell out of me)
thanks :)
One more thing:
pDoFileDownload(L"URL");
because when you're using UNICODE, you're using UNICODE.
If you're reading the URL from user input, or something else that isn't known at compile time, you'll need the MultiByteToWideChar function::)Code:string WideToANSI(const wstring &sIn) {
int iReq = WideCharToMultiByte(CP_ACP, 0, sIn.c_str(), -1, NULL, 0, NULL, NULL);
char *pcBuf = new char[iReq];
WideCharToMultiByte(CP_ACP, 0, sIn.c_str(), -1, pcBuf, iReq, NULL, NULL);
string sTemp = pcBuf;
delete[] pcBuf;
return sTemp;
}
wstring ANSIToWide(const string &sIn) {
int iReq = MultiByteToWideChar(CP_ACP, 0, sIn.c_str(), -1, NULL, 0);
wchar_t *pcBuf = new wchar_t[iReq];
MultiByteToWideChar(CP_ACP, 0, sIn.c_str(), -1, pcBuf, iReq);
wstring sTemp = pcBuf;
delete[] pcBuf;
return sTemp;
}
The stream classes do know wchar_t, so when you're using cin, you don't need to convert, cin does that for you.
It never seemed to do that properly before - probably a buggy implementation ;) *looks daggers at microsoft*
:D
What if you're looking it up from the Registry then, or from user input in a text box...
PS: Most of this stuff will be transparent when you stick to C++, but the Windows API isn't template-based (yet ;)) so you have to mess around sometimes.
PPS: I wonder if that transparent conversion extends to stringstreams...