1

Can I use URLOpenBlockingStream on win32 console application ?

I have a simple code:

#include "stdafx.h"
#include <urlmon.h>
#include <iostream>

using namespace std;

bool url(){

LPCWSTR pfile(NULL);
HRESULT hRez = URLDownloadToFile( NULL, _T("www.google.com"), (pfile), 0, NULL );
if( hRez == 0 ){
return 1;
// download ok
}
else{

return 0;// download failed
}
}

int _tmain(int argc, _TCHAR* argv[])
{

cout<< url();
return 0;
}

and it returns compiler error

All outputs are up-to-date.
1>vvconsole.obj : error LNK2019: unresolved external symbol _URLDownloadToFileW@20 referenced in      function "bool __cdecl url(void)" (?url@@YA_NXZ)
1>C:\Users\Prem kumar Sekaran\Documents\Visual Studio 2010\Projects\vvconsole\Debug\vvconsole.exe   : fatal error LNK1120: 1 unresolved externals
1>Build FAILED.

I am using built in libraries, Do I still need to link the .lib file ?

prem
  • 31
  • 5

2 Answers2

4

URLDownloadToFile() requires the header urlmon.h and urlmon.lib library. Add below line to the top of your code to link this library.

#pragma comment(lib, "urlmon.lib")
foobar
  • 2,887
  • 2
  • 30
  • 55
0
#include "stdafx.h"
#include <urlmon.h>
#include <iostream>

#pragma comment(lib, "urlmon")
using namespace std;


bool url(){

LPCWSTR pfile(NULL);
HRESULT hRez = URLDownloadToFile( NULL, _T("www.google.com"), (pfile), 0, NULL );
if( hRez == 0 ){
return 1;
// download ok
}
else{

return 0;// download failed
}
}

int _tmain(int argc, _TCHAR* argv[])
{

cout<< url();
return 0;
}
wshcdr
  • 935
  • 2
  • 12
  • 27