|
hi there. i am new to this forum.
i was wondering if there was a way you could use C++ to retrieve an image off the web and store it in a file? For Instance, if i want a hurricane image off of weather.com then it would be neat if there was a C++ call or calls to allow you to grab that image(.jpeg or bitmap or whatever) off the web at any given point and store it in a folder or wherever.
Is this possible? PLEASE HELP!!!!!!!!
|
|
|
|
|
http://www.codeproject.com/internet/webgrab.asp
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
You can use WinInet calls (starting with InternetOpenUrl or HttpOpenRequest), or use URLDownloadToFile to have IE do it for you. (See this article[^] for more info)
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Sure, anything is possible. Internet Explorer, after all, is just C++ under the hood. That said, it's not a trivial task If you're not against using MFC, take a look at CInternetSession, CHttpConnection, and CHttpFile. If the name of the JPG you're looking for constantly changes, you'll have to parse the containing HTML to figure it out every time. If the name stays the same, you're golden and only have to pull down that single file.
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
hey thanks all to have replyed so far .
well in fact this is my situation in more detail. i am looking to get the picture off the web of the current hurricane over cuba and heading into the Gulf of Mexico. The Picture from this website changes every 15 mins, coming from a satellite picture. so what i want to do is for my C++ program to be able to go out to this site and grab the NEW "frame" or updated frame of the picture. the name of the file doesnt change i dont think but of course where the hurricane is does. every 15 mins i want to store the pics in a folder and then i can use them later for whatever i want. if i have been unclear this here is the link where i am looking at.
http://www.goes.noaa.gov/browsh2.html
write back and thanks....again, this helps
|
|
|
|
|
hey thanks. ill check out those links...if i just want to do this the first way how to i implement the InternetOpenUrl or HttpOpenRequest you spoke of?? i am a pretty good C++ programmer but this aspect of the language i have never tackled. thanks for your info. also i wrote to tyMatthews a more detailed write up of what i am doing. thanks again
|
|
|
|
|
hey thanks.
ill check out those links...if i just want to do this the first way how to i implement the InternetOpenUrl or HttpOpenRequest you spoke of??
i am a pretty good C++ programmer but this aspect of the language i have never tackled. thanks for your info. also i wrote to tyMatthews a more detailed write up of what i am doing. thanks again
|
|
|
|
|
This wont compile:
{
char * dataBaseName = "abc";
BSTR b_dataBaseName = SysAllocString (dataBaseName);
}
error is:
SysAllocString' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
Any help is appreciated.
Thanks,
ns
Thanks,
ns
|
|
|
|
|
The parameter must be a unicode string.
Jason Henderson start page articles "If you are going through hell, keep going." - Sir Winston Churchill
|
|
|
|
|
SysAllocString (L"abc");
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Thanks. Actually its coming from an editbox so
mEdit.GetWindowText(myTExt);
char* newString = new char[myText.GetLength()+1);
so how do I make newString into a unicode string or the L("abc") like you said?
Thanks,
ns
|
|
|
|
|
If you have a CString, then it has a built in member to give you a BSTR,
namely
AllocSysString (done that way to avoid/promote confusion, I guess).
The BSTR contains a copy of the original string, so changes to the CString won't affect the BSTR, and remember that at some stage, you'll need to call SysFreeString and have it destroy the BSTR.
Steve S
[This signature space available for rent]
|
|
|
|
|
If I understood you, I tried this:
CString abc = "anb";
BSTR b_dataBaseName = SysAllocString (abc);
}
but got:
: error C2664: 'SysAllocString' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *'
Thanks,
ns
|
|
|
|
|
myText.AllocSysString() will return a new BSTR for you. At least it did in VC6.
|
|
|
|
|
Your method worked. It compiles! I was using SysAllocString (also exists). Now question is how to free this?
I didnt see a FreeSysString or SysFreeString matching the AllocSysString.....?
I was told that SysAllocString MUST be followed by SysFreeString, so I'm looking for this sort of matching function to go with AllocSysString...
Thanks,
ns
|
|
|
|
|
Use SysFreeString.
Jason Henderson start page articles "If you are going through hell, keep going." - Sir Winston Churchill
|
|
|
|
|
MSDN says SysFreeString frees stuff made from SysAllocString. I used AllocSysString().OK. I found this in MSDN just now for AllocSysString :
In the rare case the client receiving the returned string does not free memory in the string, you might have to free it yourself by using ::SysFreeString.
MSDN contradicts itself (unless I misunderstand):
SysFreeString Parameters
bstr
Unicode string that was allocated previously, or NULL. <code>If NULL, the function simply returns</code>.
Return Values
None.
Remarks
Passing into this function any invalid and, under some circumstances, <code>NULL pointers will result in unexpected termination of the application.</code>
I wonder which statement is true....suggestions?
Thanks,
ns
|
|
|
|
|
If you are passing this BSTR into a function, the function will usually free it. That doesn't mean it will free it.
Use SysFreeString.
Jason Henderson start page articles "If you are going through hell, keep going." - Sir Winston Churchill
|
|
|
|
|
I thought that's what I'd written ....
Steve S
[This signature space available for rent]
|
|
|
|
|
I know this one has been asked before... so much so that CG wrote an article about it.
I need to do string formatting using std::strings.
The actual problem is this: I need "trace" methods with variable arguments.
void Trace(const char *szFormat, ...);
Using MFC, I can just use CString.FormatV() or whatever, but I can't see a way to do it with std::strings without parsing the format string myself.
So I'm thinking that I'm looking at the problem the wrong way. Can any of you think of a way to do what I want?
J
|
|
|
|
|
you can always use sprintf (and friends).
std::string stdStringFmt(const char* fmt, ...)
{
const int TBUFSIZE= 2000;
char tBuf[TBUFSIZE];
va_list argptr;
va_start(argptr, fmt);
_vsnprintf(tBuf, TBUFSIZE, fmt, argptr);
va_end(argptr);
std::string out = tBuf;
return out;
}
something like this..
-c
As always, it's bread and circuses. And while bread is down right now, circuses are way up.
|
|
|
|
|
That's what I have at present, but I'm trying to get around using sprintf at all.
J
|
|
|
|
|
sprintf is King.
even CString::Format uses a flavor of it.
-c
As always, it's bread and circuses. And while bread is down right now, circuses are way up.
|
|
|
|
|
In the words of the prophets:
Thou shalt foreswear the vile printf and all his horrid brethren.
J
|
|
|
|
|
You can assemble a std::ostringstream using the stream-operator <<, which is overloaded for almost any type.
To access the std::string , you would use CMyOStringStream.str() , and if you need the LPCTSTR , you would add .c_str() to convert the std::string into a dumb char array.
|
|
|
|