ssunderk said:
In my program, I should be able to access URL using the code in
VC++/VB. I would appreciate if anybody can provide a sample code.
Here's a minimal C++ program to fetch the document from an URL and save it
to a local file.
<code>
#include <windows.h>
#include <tchar.h>
#include <urlmon.h>
#include <stdio.h>
int _tmain(int argc, TCHAR* argv[])
{
if (3 != argc)
{
_tprintf(_T("usage: %0 URL out-file-name"),argv[0]);
return 1;
}
::CoInitialize(0);
TCHAR szFullName[MAX_PATH];
::GetFullPathName(argv[2],MAX_PATH,szFullName,0);
HRESULT hr = ::URLDownloadToFile(
0,
argv[1],
szFullName,
0,
0
);
::CoUninitialize();
if (FAILED(hr))
{
_tprintf(_T("Failed, hr=0x%08x\n"),hr);
return 2;
}
return 0;
}
<code>
You can also very easily fetch from URLs by using the URL Moniker. IIRC,
you can simply call CoGetObject, passing an URL as the "Display Name" and
requesting IStream as the interface. From that IStream you can read the
document into memory, copy it to disk, or whatever.
-cd