Thread: Downloading in Win32

  1. #1
    george7378
    Guest

    Downloading in Win32

    Hi everyone,

    I have the following code in my Win32 program which is supposed to download an image from the specified URL when I press the 'download' button, and then open it:

    Code:
    			
    case IDC_DOWNLOAD:
    HRESULT hr = URLDownloadToFile( NULL, L"http://www.url.com/image.jpg", L"image.bmp", 0, NULL );
    system("image.bmp");
    break;
    However, when I compile, I get this:

    Code:
    error C2664: 'URLDownloadToFileA' : cannot convert parameter 2 from 'const wchar_t [69]' to 'LPCSTR'
    I'm guessing that this is something to do with the fact that the URLDownloadToFile operation is only supposed to be used in console programs? How do I adapt it to work in Win32?

    Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If you want to use unicode string, then you need to use the correct unicode functions:
    Code:
    HRESULT hr = URLDownloadToFileW( NULL, L"http://www.url.com/image.jpg", L"image.bmp", 0, NULL );
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Go to Project Properties - General - Project Defaults - Character Set and change it to the Unicode character set.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    OMG!...

    This one tells pretty much everything.
    error C2664: 'URLDownloadToFileA' : cannot convert parameter 2 from 'const wchar_t [69]' to 'LPCSTR'
    Remove the "L" before your strings!

    EDIT: Three people posted at exactly the same time! What are the odds for that?
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. First time Creating Win32 application with UI
    By chiefmonkey in forum Windows Programming
    Replies: 9
    Last Post: 09-23-2009, 11:44 AM
  2. Console program to Win32
    By Ducky in forum Windows Programming
    Replies: 3
    Last Post: 02-25-2008, 12:46 PM
  3. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 03:51 PM