Windows API URLdl2file...
Results 1 to 4 of 4

Thread: Windows API URLdl2file...

  1. #1
    Junior Member
    Join Date
    Jul 2005
    Posts
    7

    Windows API URLdl2file...

    Please excuse if this isnot the right forum to post this...Here is something that works on vb but doesnot seem to be working with C++
    PHP Code:
    bool DownloadFile(charremotechar*local){
        return (
    URLDownloadToFile(0remote,local,0,0)==S_OK);

    its being used like this:
    PHP Code:
    LPSTR listAddr "http://kaillera.com/raw_server_list2.php";
    LPSTR srvFullRaw "C:\\srvList.raw";
    if(
    DownloadFile(listAddr,srvFullRaw))
        
    etc... 
    which doesnot seem to be working...On the other hand the same thing in vb works quite fine...
    Code:
    Public Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
        Dim lngRetVal As Long
        lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
        If lngRetVal = 0 Then DownloadFile = True
    End Function
    Sub Main()
        DownloadFile "http://kaillera.com/raw_server_list2.php", "C:\srvList.raw"
    End Sub
    Just wondering what was wrong with the C++ code and how I might go around fixing it.

    Thanks

  2. #2
    Banned
    Join Date
    Jul 2005
    Posts
    511
    (Wonders if the LPSTR type is equal to char*)

    What about:

    char* listAddr = "http://kaillera.com/raw_server_list2.php";
    char* srvFullRaw = "C:\srvList.raw";
    if(DownloadFile(listAddr,srvFullRaw))

    ???

  3. #3
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    The definition here uses LPCTSTR instead of LPSTR.. If I read this correctly it's a difference in Unicode/ANSI style strings.. You probably need to use the Unicode version..

    Another thing I remember (it's been a while) is that NULL!=0..
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  4. #4
    Banned
    Join Date
    Jul 2005
    Posts
    511
    SirDice, Quick check... He calls URLDownloadToFileA and the A at the end suggests this is the ASCII-version of this functioncall. If he had used URLDownloadToFileW then I would agree with you that he needs WideChar (Unicode) strings here.

    However, the C code that's posted here doesn't tell us which version of this procedure is actually loaded here. You could be right that this function in C++ links to the Unicode version while the version in VB is linked to the ASCII version.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •