Results 1 to 5 of 5

Thread: [RESOLVED] API alternative to Inet.OpenURL

  1. #1

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Resolved [RESOLVED] API alternative to Inet.OpenURL

    All I need to do is download the text source of a webpage. I normally would use the inet control's OpenURL method for this, but I would like to do this in a reference-less project.

    Is there an API way to do it?

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: API alternative to Inet.OpenURL

    This is what I usually use,

    URLText$ = GoWinInet("http://www.vbforums.com/")

    btw, heres the URL to the flags and descriptions.
    WinINet Constants - API Flags
    Attached Files Attached Files
    Last edited by Edgemeal; Jan 19th, 2009 at 06:23 AM.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: API alternative to Inet.OpenURL

    you can also use the urldownloadtofile API
    vb Code:
    1. Private 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
    2. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    3.     Dim lngRetVal As Long
    4.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    5.     If lngRetVal = 0 Then DownloadFile = True
    6. End Function
    also pays to clear cache
    vb Code:
    1. Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
    2.    Alias "DeleteUrlCacheEntryA" _
    3.   (ByVal lpszUrlName As String) As Long
    4.   'ensure this file does not exist in the cache
    5.    Call DeleteUrlCacheEntry(sSourceUrl)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: API alternative to Inet.OpenURL

    There is also VB's AsyncRead method, built into the runtime.

    Search threads here and a sample in the CodeBank.

  5. #5

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: API alternative to Inet.OpenURL

    Quick and painless, and exactly what I was hoping for. Thanks much, guys.

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