Computing.Net > Forums > Programming > wininet.dll API for VB6 HELP!

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

wininet.dll API for VB6 HELP!

Reply to Message Icon

Original Message
Name: siteforge (by Greg Apel)
Date: December 15, 2005 at 07:07:34 Pacific
Subject: wininet.dll API for VB6 HELP!
OS: WinXP Pro
CPU/Ram: 800mhz AMD Duron
Comment:

Hello, I am new to this forum. This is my first post, yet it is an ugly problem I am having.

I am attempting to use the wininet.dll API to download a file from my ftp server for use in a Visual Basic 6.0 application. Just about every website I visit has some sort of tutorial saying how "easy" it is to call these functions, but it is escaping me.

Here is my code - and I appreciate any assistance offered:

Option Explicit
'******* START DECLARATIONS FOR WININET.DLL FTP CONNECTION *******

Const scUserAgent = "vb wininet"

Const INTERNET_SERVICE_FTP = 1
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_FLAG_PASSIVE = &H8000000
Const FTP_TRANSFER_TYPE_BINARY = 0
Const FILE_ATTRIBUTE_ARCHIVE = &H20

Private Declare Function InternetOpen _
Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long

Private Declare Function InternetConnect _
Lib "wininet.dll" Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long

Private Declare Function FtpGetFile _
Lib "wininet.dll" ( _
ByVal hConnect As Long, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFileExists As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As LoadResConstants

Private Declare Function InternetCloseHandle _
Lib "wininet.dll" (ByVal hInet As Long) As Integer

'******* END DECLARATIONS FOR WININET.DLL FTP CONNECTION *******

Private Sub Command1_Click()

'handles for connection
Dim hOpen&, hConn&
'long for return values
Dim lRes As Long

hOpen = InternetOpen(scUserAgent, _ INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, vbNullString, 0)

hConn = InternetConnect(hOpen, _ "ftp.my_site.com", "21", _
"my_username", "my_password", _
INTERNET_SERVICE_FTP, _
INTERNET_FLAG_PASSIVE, 0)

lRes = FtpGetFile(hConn, _
"some_file.zip", "C:\some_file.zip", _
False, FILE_ATTRIBUTE_ARCHIVE, _
FTP_TRANSFER_TYPE_BINARY, 0&)

'yep, closes connection
InternetCloseHandle hConn
InternetCloseHandle hOpen
End Sub
'************ END OF PROGRAM *************

Okay, that's pretty much it. A form, a command button called Command1, and the code therein.

When I click on the command button, I see network activity on my monitor, but then after a few seconds, I receive this error:
Can't find DLL entry point FTPGetFile in wininet.dll

Help, please?


Report Offensive Message For Removal


Response Number 1
Name: StuartS
Date: December 15, 2005 at 07:53:42 Pacific
Reply: (edit)

I have looked at it and everything looks fine, except possibly the function declaration.

Try this version. It is slightly different than yours. Yours has no Alias.

Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean


Stuart


Report Offensive Follow Up For Removal

Response Number 2
Name: siteforge (by Greg Apel)
Date: December 15, 2005 at 08:11:25 Pacific
Reply: (edit)

StuartS!

You're the man :)

That solved my problem perfectly. I suppose I should have asked for help a week ago. I've been at it for to long on my own and have tried approximately 20 different versions of the same thing to no avail.

Thank you for the quick response. This forum is great!

- Greg Apel -


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software