-
Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
Hi all,
I was really disappointed when I started to write a library (a DLL component)
and I had to add a form only to hold the Microsoft Internet Transfer Control
6.0. Does anyone actually knows if there any API call that can be declared
in the class so that I dont really need to add an additional form.
Your answer would be very much appreciated
Uri
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
You're looking for the WinInet library (wininet.dll). Check out
<http://msdn.microsoft.com/workshop/n...et/wininet.asp>
--
Michael Shutt
Please respond to newsgroup as I will not return direct emails.
"Yuri" <uria@cck.com.au> wrote in message news:3b0307be$1@news.devx.com...
>
> Hi all,
> I was really disappointed when I started to write a library (a DLL
component)
> and I had to add a form only to hold the Microsoft Internet Transfer
Control
> 6.0. Does anyone actually knows if there any API call that can be declared
> in the class so that I dont really need to add an additional form.
>
> Your answer would be very much appreciated
>
> Uri
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
"Michael Shutt" <mshutt@mediaone.net> wrote:
>You're looking for the WinInet library (wininet.dll). Check out
><http://msdn.microsoft.com/workshop/n...et/wininet.asp>
>
>--
>Michael Shutt
Yuri -
Whilst Michael has given you the correct API, I ought to warn you that there
is quite an amount of overhead when using these functions. It may well be
worth continuing with the Inet control on the form, but also encapsulate
it within the form.
The MSDN documentation _does_ suggest that you can instantiate it like a
class, but in my experience this is highly unstable and almost always crashes
at the first method call.
One alternative may be to buy a 3rd party component. Apparently, the Mabry
internet library is pretty good.
--
Mark Alexander Bertenshaw
Programmer/Analyst
Chordiant Software, Inc.
Brentford
UK
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
I use the catalyst socketwrench both on a form, and by with early binding (like a class). The site has lots of examples, and is
freeware.
Have a look at www.catalyst.com
--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer
iCode Systems
"Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message news:3b03bdc7$1@news.devx.com...
>
> "Michael Shutt" <mshutt@mediaone.net> wrote:
> >You're looking for the WinInet library (wininet.dll). Check out
> ><http://msdn.microsoft.com/workshop/n...et/wininet.asp>
> >
> >--
> >Michael Shutt
>
> Yuri -
>
> Whilst Michael has given you the correct API, I ought to warn you that there
> is quite an amount of overhead when using these functions. It may well be
> worth continuing with the Inet control on the form, but also encapsulate
> it within the form.
>
> The MSDN documentation _does_ suggest that you can instantiate it like a
> class, but in my experience this is highly unstable and almost always crashes
> at the first method call.
>
> One alternative may be to buy a 3rd party component. Apparently, the Mabry
> internet library is pretty good.
>
> --
> Mark Alexander Bertenshaw
> Programmer/Analyst
> Chordiant Software, Inc.
> Brentford
> UK
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
The Internet Transfer control is just a wrapper for the WinInet API, so any
overhead you incur with wininet.dll will just be increased by using
msinet.ocx.
--
Michael Shutt
Please respond to newsgroup as I will not return direct emails.
"Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
news:3b03bdc7$1@news.devx.com...
>
> "Michael Shutt" <mshutt@mediaone.net> wrote:
> >You're looking for the WinInet library (wininet.dll). Check out
> ><http://msdn.microsoft.com/workshop/n...et/wininet.asp>
> >
> >--
> >Michael Shutt
>
> Yuri -
>
> Whilst Michael has given you the correct API, I ought to warn you that
there
> is quite an amount of overhead when using these functions. It may well be
> worth continuing with the Inet control on the form, but also encapsulate
> it within the form.
>
> The MSDN documentation _does_ suggest that you can instantiate it like a
> class, but in my experience this is highly unstable and almost always
crashes
> at the first method call.
>
> One alternative may be to buy a 3rd party component. Apparently, the
Mabry
> internet library is pretty good.
>
> --
> Mark Alexander Bertenshaw
> Programmer/Analyst
> Chordiant Software, Inc.
> Brentford
> UK
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
"Michael Shutt" <mshutt@mediaone.net> wrote in message
news:3b0400cb$1@news.devx.com...
> The Internet Transfer control is just a wrapper for the WinInet API, so
any
> overhead you incur with wininet.dll will just be increased by using
> msinet.ocx.
>
> --
> Michael Shutt
Quite true, but you still have to write code to interface with the WinInet
DLL which in itself is an overhead. I suppose it depends on how much of the
DLL's features you require.
--
Mark Alexander Bertenshaw
Programmer/Analyst
Chordiant Software, Inc.
Brentford
UK
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
I feel your pain Yuri =). I get so frustrated with that crap -- half the
things written as "controls" should really be a DLL. Oh well.
It's really not too difficult to use the winnet, and it works "well enough"
for most cases (which is exactly what the control uses). 3RD party DLL's
doesn't really mean "better" -- if you start banging on them hard enough
they too can crumble. Wininet sure beats beats writing to the RFC's.
Below please find an *example* routine that downloads an URL (FTP or HTTP).
The subject example performs a UUEncode of the input file before writing it
to an output file, but you can modify it to suit your needs. You will need
to fetch the declares too.
I've also included a little file (CheckSumFiles.EXE) which is helpfull when
you are writing code that performs a file copy -- it ensures that the file
is identical to the source.
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Monte Hansen
http://KillerVB.com
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Private Function UUEncodeURL(ByVal iFile As Long, _
ByVal Url As String, _
Optional ByVal UserName As String, _
Optional ByVal Password As String, _
Optional ByVal Passive As Boolean, _
Optional ByVal OpenFlags As Long, _
Optional ByVal Mode As Long) As Long
'===========================================================================
' UUEncodeURL - Downloads the contents of an URL. Only IE's
' INTERNET_OPEN_TYPE_PRECONFIG connection mode is supported for this
' function.
'
' iFile The VB-style file number to write into [output file].
' URL The URL to download [input file]
' UserName,
' Password Authentication fields for FTP server only.
' Passive FTP Passive option.
' OpenFlags See the SDK for InternetOpenUrl/FtpOpenFile for dwFlags.
' Mode Unix style permissions.
'
' RETURNS The # of bytes written.
'
' NOTE: This function does not support file splitting. Newsgroups may
' reject large attachments not broken into 1000 line segments.
'===========================================================================
Const INTERNET_OPEN_TYPE_PRECONFIG = 0&
Const INTERNET_INVALID_PORT_NUMBER = 0& ' // use the protocol-specific
default
Const INTERNET_SERVICE_FTP = 1&
Const INTERNET_SERVICE_HTTP = 3&
Const INTERNET_FLAG_PASSIVE = &H8000000 ' // used for FTP connections
Const GENERIC_READ = &H80000000
Const PageSize As Long = 4096 ' block size of URL reads
' Given this URL
"ftp://ftp.microsoft.com/softlib/mslfiles/jet40sp4.exe":
Dim ProtocolName As String ' ftp:// or http://
Dim ServerName As String ' ftp.microsoft.com
Dim FolderName As String ' softlib/mslfiles
Dim FileName As String ' jet40sp4.exe
Dim Prefix As String ' Char whose ascii code is line
length
Dim BufferPg() As Byte ' Big input buffer: just shy of
4K chunks
Dim BufferIn() As Byte ' Input buffer if size
UUChunkSize
Dim BufferOut() As Byte ' UUEncoded output
Dim hInternet As Long ' Connection to the internet
Dim hFTP As Long ' Connection to the FTP server
Dim hFile As Long ' Handle to open file
Dim cbBufferPg As Long ' # of downloaded bytes [ANSI]
Dim cbBufferIn As Long ' # of bytes to be encoded
Dim cbPgRead As Long ' # of bytes read on single read
Dim cbTotalRead As Long ' # of bytes read (in total)
Dim cbEncoded As Long ' # of bytes encoded in BufferPg
Dim cbToEncode As Long ' # of bytes in BufferIn to
encoded
Dim Success As Boolean ' Duh
Dim nErr As Long ' We trap & throw errors back to
caller.
Dim sErr As String
' Trap all errors for resource cleanup.
' Errors will be thrown internally too.
On Error GoTo ErrHandler
' Tokenize URL into segments
ParseURL Url, ProtocolName, ServerName, FolderName
FileName = FileFromPath(Url)
'*************************************************
' This section connects to the Internet, the
' remote server, and then opens the file.
'*************************************************
' Open Inet connection
hInternet = InternetOpen(App.ProductName, _
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, _
vbNullString, _
0&)
' Notify caller if failed
If Not IsValidHandle(hInternet) Then
ApiRaise Err.LastDllError, Module, "Could not connect to the
internet."
End If
' Open the file.
If LCase$(ProtocolName) Like "ftp:*" Then
' An empty UserID is NULL.
If Len(UserName) = 0 Then
UserName = vbNullString
' We only NULL the password if both are empty strings,
' otherwise it's legal to have an empty string as a
' password.
If Len(Password) = 0 Then
Password = vbNullString
End If
End If
' For FTP, we must first connect to the FTP server
' before we can open the file.
hFTP = InternetConnect(hInternet, ProtocolName & ServerName, _
INTERNET_INVALID_PORT_NUMBER, UserName, Password, _
INTERNET_SERVICE_FTP, _
IIf(Passive, INTERNET_FLAG_PASSIVE, 0), 0)
If Not IsValidHandle(hFTP) Then
ApiRaise Err.LastDllError, Module, _
"Could not connect to FTP server " & ServerName & "."
End If
' Change the current directory. My experience
' reveals that this is better than using a
' full path spec in FtpOpenFile.
Success = FtpSetCurrentDirectory(hFTP, _
IIf(Len(FolderName) = 0, "/", FolderName))
If Not Success Then
ApiRaise Err.LastDllError, Module, _
"Could not set current directory to " & FolderName & "."
End If
hFile = FtpOpenFile(hFTP, FileName, GENERIC_READ, OpenFlags, 0&)
Else ' HTTP(S) protocol. Anything else raises an error.
hFile = InternetOpenUrl(hInternet, _
Url, ByVal 0&, 0&, OpenFlags, 0&)
End If
' Throw error if file open failed.
If Not IsValidHandle(hFile) Then
ApiRaise Err.LastDllError, Module, _
"Could not open file " & Url & "."
End If
' Build & write the header part of the attachment.
BufferIn = StrConv(UUHeader & Format$(Mode, "000") _
& " " & FileName & vbCrLf, vbFromUnicode)
Put #iFile, , BufferIn
'*************************************************
' This section reads the file. A double loop is
' needed cuz we download the file in ~4K chunks.
' For each chunk, we will encode 1 45-byte line at
' a time. We do this cuz downloading a file 45
' bytes at a time sux. 4-8K is optimal for a slow
' WAN (or dialup) connection.
'*************************************************
' Initialize array to max # of encoded
' lines that can fit within a 4K chunk.
cbBufferPg = Fix(PageSize \ UUChunkSize)
cbBufferPg = cbBufferPg * PageSize
ReDim BufferPg(cbBufferPg - 1)
' Begin downloading the file
Do
' Read the next chunk. Keep running sum of bytes downloaded.
Success = InternetReadFile(hFile, ByVal VarPtr(BufferPg(0)), _
cbBufferPg, cbPgRead)
If Not Success Then
ApiRaise Err.LastDllError, Module, _
"There was an error attempting to read file " & Url & "."
ElseIf cbPgRead = 0 Then
' reached end of file.
Exit Do
End If
' Track # of bytes read from file.
cbTotalRead = cbTotalRead + cbPgRead
' Encode the contents of BufferPg, 1 line at a time.
cbEncoded = 0
cbToEncode = UUChunkSize
Prefix = Chr$(UUChunkSize + 32)
ReDim BufferIn(UUChunkSize - 1)
Do While cbEncoded < cbPgRead
' Reduce size if last line and not full length.
' Otherwise, encode a full chunk, using default
' stuff set before the loop.
If (cbPgRead - cbEncoded) < UUChunkSize Then
cbToEncode = (cbPgRead - cbEncoded)
Prefix = Chr$((cbPgRead - cbEncoded) + 32)
ReDim BufferIn(cbToEncode - 1)
End If
' Copy bytes to encode into small work area.
CopyMemory ByVal VarPtr(BufferIn(0)), _
ByVal VarPtr(BufferPg(cbEncoded)), cbToEncode
' Encode the buffer
UUEncodeStream BufferIn, BufferOut, Prefix, vbCrLf
' Write the encoded line for attachment.
Put #iFile, , BufferOut
' Keep track of # bytes encoded in the buffer.
cbEncoded = cbEncoded + cbToEncode
Loop ' [Next chunk of file to encode]
Loop ' [Next chunk of file to read]
ExitLabel:
' Return # of bytes written to output file.
UUEncodeURL = cbEncoded
' Close connections. Bottom up since
' InternetCloseHandle will recurse.
If IsValidHandle(hFile) Then
InternetCloseHandle hFile
End If
If IsValidHandle(hInternet) Then
InternetCloseHandle hInternet
End If
' Throw error to caller if any
If nErr <> 0 Then
On Error GoTo 0
Err.Raise nErr, Module, sErr
End If
Exit Function
Resume
ErrHandler:
Debug.Assert 0
' Save error info and resume
nErr = Err.Number
sErr = Err.Description
Resume ExitLabel
End Function
"Yuri" <uria@cck.com.au> wrote in message news:3b0307be$1@news.devx.com...
>
> Hi all,
> I was really disappointed when I started to write a library (a DLL
component)
> and I had to add a form only to hold the Microsoft Internet Transfer
Control
> 6.0. Does anyone actually knows if there any API call that can be declared
> in the class so that I dont really need to add an additional form.
>
> Your answer would be very much appreciated
>
> Uri
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
You're looking for the WinInet library (wininet.dll). Check out
<http://msdn.microsoft.com/workshop/n...et/wininet.asp>
--
Michael Shutt
Please respond to newsgroup as I will not return direct emails.
"Yuri" <uria@cck.com.au> wrote in message news:3b0307be$1@news.devx.com...
>
> Hi all,
> I was really disappointed when I started to write a library (a DLL
component)
> and I had to add a form only to hold the Microsoft Internet Transfer
Control
> 6.0. Does anyone actually knows if there any API call that can be declared
> in the class so that I dont really need to add an additional form.
>
> Your answer would be very much appreciated
>
> Uri
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
"Michael Shutt" <mshutt@mediaone.net> wrote:
>You're looking for the WinInet library (wininet.dll). Check out
><http://msdn.microsoft.com/workshop/n...et/wininet.asp>
>
>--
>Michael Shutt
Yuri -
Whilst Michael has given you the correct API, I ought to warn you that there
is quite an amount of overhead when using these functions. It may well be
worth continuing with the Inet control on the form, but also encapsulate
it within the form.
The MSDN documentation _does_ suggest that you can instantiate it like a
class, but in my experience this is highly unstable and almost always crashes
at the first method call.
One alternative may be to buy a 3rd party component. Apparently, the Mabry
internet library is pretty good.
--
Mark Alexander Bertenshaw
Programmer/Analyst
Chordiant Software, Inc.
Brentford
UK
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
I use the catalyst socketwrench both on a form, and by with early binding (like a class). The site has lots of examples, and is
freeware.
Have a look at www.catalyst.com
--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer
iCode Systems
"Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message news:3b03bdc7$1@news.devx.com...
>
> "Michael Shutt" <mshutt@mediaone.net> wrote:
> >You're looking for the WinInet library (wininet.dll). Check out
> ><http://msdn.microsoft.com/workshop/n...et/wininet.asp>
> >
> >--
> >Michael Shutt
>
> Yuri -
>
> Whilst Michael has given you the correct API, I ought to warn you that there
> is quite an amount of overhead when using these functions. It may well be
> worth continuing with the Inet control on the form, but also encapsulate
> it within the form.
>
> The MSDN documentation _does_ suggest that you can instantiate it like a
> class, but in my experience this is highly unstable and almost always crashes
> at the first method call.
>
> One alternative may be to buy a 3rd party component. Apparently, the Mabry
> internet library is pretty good.
>
> --
> Mark Alexander Bertenshaw
> Programmer/Analyst
> Chordiant Software, Inc.
> Brentford
> UK
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
The Internet Transfer control is just a wrapper for the WinInet API, so any
overhead you incur with wininet.dll will just be increased by using
msinet.ocx.
--
Michael Shutt
Please respond to newsgroup as I will not return direct emails.
"Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
news:3b03bdc7$1@news.devx.com...
>
> "Michael Shutt" <mshutt@mediaone.net> wrote:
> >You're looking for the WinInet library (wininet.dll). Check out
> ><http://msdn.microsoft.com/workshop/n...et/wininet.asp>
> >
> >--
> >Michael Shutt
>
> Yuri -
>
> Whilst Michael has given you the correct API, I ought to warn you that
there
> is quite an amount of overhead when using these functions. It may well be
> worth continuing with the Inet control on the form, but also encapsulate
> it within the form.
>
> The MSDN documentation _does_ suggest that you can instantiate it like a
> class, but in my experience this is highly unstable and almost always
crashes
> at the first method call.
>
> One alternative may be to buy a 3rd party component. Apparently, the
Mabry
> internet library is pretty good.
>
> --
> Mark Alexander Bertenshaw
> Programmer/Analyst
> Chordiant Software, Inc.
> Brentford
> UK
>
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
"Michael Shutt" <mshutt@mediaone.net> wrote in message
news:3b0400cb$1@news.devx.com...
> The Internet Transfer control is just a wrapper for the WinInet API, so
any
> overhead you incur with wininet.dll will just be increased by using
> msinet.ocx.
>
> --
> Michael Shutt
Quite true, but you still have to write code to interface with the WinInet
DLL which in itself is an overhead. I suppose it depends on how much of the
DLL's features you require.
--
Mark Alexander Bertenshaw
Programmer/Analyst
Chordiant Software, Inc.
Brentford
UK
-
Re: Microsoft Internet Transfer Control 6.0 - what would be the API for that ?
I feel your pain Yuri =). I get so frustrated with that crap -- half the
things written as "controls" should really be a DLL. Oh well.
It's really not too difficult to use the winnet, and it works "well enough"
for most cases (which is exactly what the control uses). 3RD party DLL's
doesn't really mean "better" -- if you start banging on them hard enough
they too can crumble. Wininet sure beats beats writing to the RFC's.
Below please find an *example* routine that downloads an URL (FTP or HTTP).
The subject example performs a UUEncode of the input file before writing it
to an output file, but you can modify it to suit your needs. You will need
to fetch the declares too.
I've also included a little file (CheckSumFiles.EXE) which is helpfull when
you are writing code that performs a file copy -- it ensures that the file
is identical to the source.
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Monte Hansen
http://KillerVB.com
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Private Function UUEncodeURL(ByVal iFile As Long, _
ByVal Url As String, _
Optional ByVal UserName As String, _
Optional ByVal Password As String, _
Optional ByVal Passive As Boolean, _
Optional ByVal OpenFlags As Long, _
Optional ByVal Mode As Long) As Long
'===========================================================================
' UUEncodeURL - Downloads the contents of an URL. Only IE's
' INTERNET_OPEN_TYPE_PRECONFIG connection mode is supported for this
' function.
'
' iFile The VB-style file number to write into [output file].
' URL The URL to download [input file]
' UserName,
' Password Authentication fields for FTP server only.
' Passive FTP Passive option.
' OpenFlags See the SDK for InternetOpenUrl/FtpOpenFile for dwFlags.
' Mode Unix style permissions.
'
' RETURNS The # of bytes written.
'
' NOTE: This function does not support file splitting. Newsgroups may
' reject large attachments not broken into 1000 line segments.
'===========================================================================
Const INTERNET_OPEN_TYPE_PRECONFIG = 0&
Const INTERNET_INVALID_PORT_NUMBER = 0& ' // use the protocol-specific
default
Const INTERNET_SERVICE_FTP = 1&
Const INTERNET_SERVICE_HTTP = 3&
Const INTERNET_FLAG_PASSIVE = &H8000000 ' // used for FTP connections
Const GENERIC_READ = &H80000000
Const PageSize As Long = 4096 ' block size of URL reads
' Given this URL
"ftp://ftp.microsoft.com/softlib/mslfiles/jet40sp4.exe":
Dim ProtocolName As String ' ftp:// or http://
Dim ServerName As String ' ftp.microsoft.com
Dim FolderName As String ' softlib/mslfiles
Dim FileName As String ' jet40sp4.exe
Dim Prefix As String ' Char whose ascii code is line
length
Dim BufferPg() As Byte ' Big input buffer: just shy of
4K chunks
Dim BufferIn() As Byte ' Input buffer if size
UUChunkSize
Dim BufferOut() As Byte ' UUEncoded output
Dim hInternet As Long ' Connection to the internet
Dim hFTP As Long ' Connection to the FTP server
Dim hFile As Long ' Handle to open file
Dim cbBufferPg As Long ' # of downloaded bytes [ANSI]
Dim cbBufferIn As Long ' # of bytes to be encoded
Dim cbPgRead As Long ' # of bytes read on single read
Dim cbTotalRead As Long ' # of bytes read (in total)
Dim cbEncoded As Long ' # of bytes encoded in BufferPg
Dim cbToEncode As Long ' # of bytes in BufferIn to
encoded
Dim Success As Boolean ' Duh
Dim nErr As Long ' We trap & throw errors back to
caller.
Dim sErr As String
' Trap all errors for resource cleanup.
' Errors will be thrown internally too.
On Error GoTo ErrHandler
' Tokenize URL into segments
ParseURL Url, ProtocolName, ServerName, FolderName
FileName = FileFromPath(Url)
'*************************************************
' This section connects to the Internet, the
' remote server, and then opens the file.
'*************************************************
' Open Inet connection
hInternet = InternetOpen(App.ProductName, _
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, _
vbNullString, _
0&)
' Notify caller if failed
If Not IsValidHandle(hInternet) Then
ApiRaise Err.LastDllError, Module, "Could not connect to the
internet."
End If
' Open the file.
If LCase$(ProtocolName) Like "ftp:*" Then
' An empty UserID is NULL.
If Len(UserName) = 0 Then
UserName = vbNullString
' We only NULL the password if both are empty strings,
' otherwise it's legal to have an empty string as a
' password.
If Len(Password) = 0 Then
Password = vbNullString
End If
End If
' For FTP, we must first connect to the FTP server
' before we can open the file.
hFTP = InternetConnect(hInternet, ProtocolName & ServerName, _
INTERNET_INVALID_PORT_NUMBER, UserName, Password, _
INTERNET_SERVICE_FTP, _
IIf(Passive, INTERNET_FLAG_PASSIVE, 0), 0)
If Not IsValidHandle(hFTP) Then
ApiRaise Err.LastDllError, Module, _
"Could not connect to FTP server " & ServerName & "."
End If
' Change the current directory. My experience
' reveals that this is better than using a
' full path spec in FtpOpenFile.
Success = FtpSetCurrentDirectory(hFTP, _
IIf(Len(FolderName) = 0, "/", FolderName))
If Not Success Then
ApiRaise Err.LastDllError, Module, _
"Could not set current directory to " & FolderName & "."
End If
hFile = FtpOpenFile(hFTP, FileName, GENERIC_READ, OpenFlags, 0&)
Else ' HTTP(S) protocol. Anything else raises an error.
hFile = InternetOpenUrl(hInternet, _
Url, ByVal 0&, 0&, OpenFlags, 0&)
End If
' Throw error if file open failed.
If Not IsValidHandle(hFile) Then
ApiRaise Err.LastDllError, Module, _
"Could not open file " & Url & "."
End If
' Build & write the header part of the attachment.
BufferIn = StrConv(UUHeader & Format$(Mode, "000") _
& " " & FileName & vbCrLf, vbFromUnicode)
Put #iFile, , BufferIn
'*************************************************
' This section reads the file. A double loop is
' needed cuz we download the file in ~4K chunks.
' For each chunk, we will encode 1 45-byte line at
' a time. We do this cuz downloading a file 45
' bytes at a time sux. 4-8K is optimal for a slow
' WAN (or dialup) connection.
'*************************************************
' Initialize array to max # of encoded
' lines that can fit within a 4K chunk.
cbBufferPg = Fix(PageSize \ UUChunkSize)
cbBufferPg = cbBufferPg * PageSize
ReDim BufferPg(cbBufferPg - 1)
' Begin downloading the file
Do
' Read the next chunk. Keep running sum of bytes downloaded.
Success = InternetReadFile(hFile, ByVal VarPtr(BufferPg(0)), _
cbBufferPg, cbPgRead)
If Not Success Then
ApiRaise Err.LastDllError, Module, _
"There was an error attempting to read file " & Url & "."
ElseIf cbPgRead = 0 Then
' reached end of file.
Exit Do
End If
' Track # of bytes read from file.
cbTotalRead = cbTotalRead + cbPgRead
' Encode the contents of BufferPg, 1 line at a time.
cbEncoded = 0
cbToEncode = UUChunkSize
Prefix = Chr$(UUChunkSize + 32)
ReDim BufferIn(UUChunkSize - 1)
Do While cbEncoded < cbPgRead
' Reduce size if last line and not full length.
' Otherwise, encode a full chunk, using default
' stuff set before the loop.
If (cbPgRead - cbEncoded) < UUChunkSize Then
cbToEncode = (cbPgRead - cbEncoded)
Prefix = Chr$((cbPgRead - cbEncoded) + 32)
ReDim BufferIn(cbToEncode - 1)
End If
' Copy bytes to encode into small work area.
CopyMemory ByVal VarPtr(BufferIn(0)), _
ByVal VarPtr(BufferPg(cbEncoded)), cbToEncode
' Encode the buffer
UUEncodeStream BufferIn, BufferOut, Prefix, vbCrLf
' Write the encoded line for attachment.
Put #iFile, , BufferOut
' Keep track of # bytes encoded in the buffer.
cbEncoded = cbEncoded + cbToEncode
Loop ' [Next chunk of file to encode]
Loop ' [Next chunk of file to read]
ExitLabel:
' Return # of bytes written to output file.
UUEncodeURL = cbEncoded
' Close connections. Bottom up since
' InternetCloseHandle will recurse.
If IsValidHandle(hFile) Then
InternetCloseHandle hFile
End If
If IsValidHandle(hInternet) Then
InternetCloseHandle hInternet
End If
' Throw error to caller if any
If nErr <> 0 Then
On Error GoTo 0
Err.Raise nErr, Module, sErr
End If
Exit Function
Resume
ErrHandler:
Debug.Assert 0
' Save error info and resume
nErr = Err.Number
sErr = Err.Description
Resume ExitLabel
End Function
"Yuri" <uria@cck.com.au> wrote in message news:3b0307be$1@news.devx.com...
>
> Hi all,
> I was really disappointed when I started to write a library (a DLL
component)
> and I had to add a form only to hold the Microsoft Internet Transfer
Control
> 6.0. Does anyone actually knows if there any API call that can be declared
> in the class so that I dont really need to add an additional form.
>
> Your answer would be very much appreciated
>
> Uri
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks