Results 1 to 12 of 12

Thread: Winsock question

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    39

    Winsock question

    I want to download a picture using only winsock,
    Is it possible to do?
    If it isn't I want to download the "source code" of the picture, and save it as a picture file,
    Is it possible to do?

  2. #2
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Winsock question

    I Think Is Possible But I'm Not Sure How
    I Will Try To Figure Out

    If Someone Else Knows It Please Help Him
    I Will Try To Make It

  3. #3
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Winsock question

    if you want to download picture from web server, you need to send the http request for it, then the server will send you the reply and picture data, which you can save..

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    39

    Re: Winsock question

    Yes I want to download the picture.
    Can you explain me this in an example code?
    For example, downloading this picture:
    http://pc.co.il/_uploads/extraimg/gindis(1).jpg

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Winsock question

    You could use the URLDownloadToFile API. I've attatched a form that demos it. Here is the code:

    VB Code:
    1. Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
    2.     "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
    3.     ByVal szFileName As String, ByVal dwReserved As Long, _
    4.     ByVal lpfnCB As Long) As Long
    5.  
    6. Private Sub command1_click()
    7.  
    8.     Dim errcode As Long
    9.     Dim url As String
    10.     Dim localFileName As String
    11.    
    12.     'WHAT FILE TO DOWNLOAD?
    13.     url = "http://pc.co.il/_uploads/extraimg/gindis(1).jpg"
    14.     'WHERE TO SAVE IT?
    15.     localFileName = "c:\gindis(1).jpg"
    16.    
    17.     errcode = URLDownloadToFile(0, url, localFileName, 0, 0)
    18.     If errcode = 0 Then
    19.         MsgBox "Download finished and saved to: " & localFileName
    20.     Else
    21.         MsgBox "Error while downloading"
    22.     End If
    23.  
    24. End Sub
    Attached Files Attached Files
    Chris

  6. #6
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Winsock question

    Is there any way to get the file's size and a progress on how much is has downloaded?

  7. #7
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473
    Chris

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    39

    Re: Winsock question

    I am asking if can I download the file using Winsock and not any API's

  9. #9
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Winsock question

    Yes you can do it with Winsock, why don't you search. It's much more difficult using winsock though, you have to have a decent grasp of Winsock and the HTTP protocol. Far easier to do it with the API.
    Chris

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    39

    Re: Winsock question

    I know its much easier, but I need help with the winsock.
    About searching, I have searche and have not found information to help me.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Winsock question

    You can download it with the Winsock control or you can download it and show progress. You might be able to download it with the Winsock control and show progress by subclassing the control, but using an API is a lot easier than subclassing.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    39

    Re: Winsock question

    never mind
    I have found how to download throught winsock.

Posting Permissions

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



Click Here to Expand Forum to Full Width