473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

wininet.dll, lastdllerror=6, what does it mean?

Hi all,
I'm trying to create a class which handles FTP. Knowing little of classes
I'm having some trouble making things work. Also having trouble finding the
meaning of some error-codes. The code below results in a lastdllerror 6 (and
no transfer)... can't find what this error means and how to solve it (yes I
already tried google). Could someone please help me out?

This code should, on button-click, connect to ftp-server (192.168.20.1), get
a file 'test.txt' from its root and store this file into 'c:\temp\test.txt'.
Result-string to 'label1'.
I created a class 'Ftp' to achieve this, without any luck sofar...

Thanks in advance!

### [ Class ]
Public Class Ftp

Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet
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 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 FtpGetFile Lib "wininet.dll" Alias
"FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal
lpszNewFile As String, ByVal fFailIfExists As Long, ByVal
dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As
Long) As Boolean

Private Declare Function FtpPutFile Lib "wininet.dll" Alias
"FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal
lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long)
As Boolean

Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll"
Alias "InternetGetLastResponseInfoA" (ByVal lpdwError As Long, ByVal
lpszBuffer As String, ByVal lpdwBufferLength As Long) As Boolean

Dim strServer, strLogin, strPassword As String
Dim INet, INetConn As Long

Property Server() As String
Get
Return strServer
End Get
Set(ByVal Value As String)
strServer = Value
End Set
End Property

Property Login() As String
Get
Return strLogin
End Get
Set(ByVal Value As String)
strLogin = Value
End Set
End Property

Property Password() As String
Get
Return strPassword
End Get
Set(ByVal Value As String)
strPassword = Value
End Set
End Property

Public Function showError()
Dim lErr As Long, sErr As String, lenBuf As Long
InternetGetLastResponseInfo(lErr, sErr, lenBuf)
sErr = lenBuf.ToString
InternetGetLastResponseInfo(lErr, sErr, lenBuf)
Return ("Error " + CStr(lErr) + ": " + sErr)
End Function

Public Sub openConnection()
INet = InternetOpen("AceGroup FTP", 0, vbNullString, vbNullString,
0)
INetConn = InternetConnect(INet, Server, 21, Login, Password, 1, 0,
0)
End Sub

Public Sub closeConnection()
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
INet = 0
INetConn = 0
End Sub

Public Function putFile(ByVal localFile As String, ByVal remoteFile As
String) As String
Dim result As String
Try
If INet = 0 Then openConnection()
result = FtpPutFile(INetConn, localFile, remoteFile, 0,
0).ToString
Catch ex As Exception
result = ex.ToString()
Finally
closeConnection()
End Try

Return result
End Function

Public Function getFile(ByVal remoteFile As String, ByVal localFile As
String) As String
Dim result As String
Try
If INet = 0 Then openConnection()
result = FtpGetFile(INetConn, remoteFile, localFile, 0, 0, 1,
0).ToString()
Catch ex As Exception
result = ex.ToString()
Finally
closeConnection()
End Try

Return result
End Function

End Class
### [Webform]
[ ... ]
Dim cFtp As Ftp = New Ftp
Dim Result As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

cFtp.Server = "192.168.20.1"
cFtp.Login = "[ my login ]"
cFtp.Password = "[ my pass ]"

cFtp.openConnection()
Result = cFtp.getFile("test.txt", "c:\temp\test.txt")
cFtp.closeConnection()
' output result to label
label1.text = Result
End Sub
Nov 20 '05 #1
8 6824
* "Sjaakie Helderhorst" <pr**********@tell.you> scripsit:
### [ Class ]
Public Class Ftp

Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet
As Long) As Long


The declares are wrong. Replace the 'Long' with 'Int32', all parameters
with name 'h*' with 'IntPtr'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
On 2004-02-05, Sjaakie Helderhorst <pr**********@tell.you> wrote:
Hi all,
I'm trying to create a class which handles FTP. Knowing little of classes
I'm having some trouble making things work. Also having trouble finding the
meaning of some error-codes. The code below results in a lastdllerror 6 (and
no transfer)... can't find what this error means and how to solve it (yes I
already tried google). Could someone please help me out?

This code should, on button-click, connect to ftp-server (192.168.20.1), get
a file 'test.txt' from its root and store this file into 'c:\temp\test.txt'.
Result-string to 'label1'.
I created a class 'Ftp' to achieve this, without any luck sofar...

Thanks in advance!

### [ Class ]
Public Class Ftp

Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet
As Long) As Long
' Handles should be IntPtr, Make this return boolean
Private Declare Function InternetCloseHandle Lib "wininet" _
(ByVal hInternet As System.IntPtr) As Boolean
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


' loose the alias - use auto, change longs to integers, change
' handles to be intptr, integers to short. I also usually create
' an enum for flags
Private Enum Services
Ftp = ...
Gopher = ...
Http = ...
End Enum

Private Enum ServiceFlags
...
End Enum

Private Declare Auto Function InternetConnect Lib "wininet" _
(ByVal hInternet As System.IntPtr, _
ByVal lpszServerName As String, _
ByVal nServerPort As Short, _
ByVal lpszUserName As String, _
ByVal lpszPassword As String, _
ByVal dwService As Services, _
ByVal dwFlags As ServiceFlags, _
ByVal lContext As Integer) As System.IntPtr
Anyway, that basic problems are you are using Longs where you should be
using Integers. Longs are 64-bit in .NET...

Long = 64-bit
Integer = 32-bit
Short = 16-bit
Also, you should not use the Alias's. You should drop them and use the
Auto modifier instead. This lets the runtime determine the proper
function to call based on the OS. Further, any handles (such as hWnd,
hInternet, etc) should be declared as IntPtr (System.IntPtr).

As for finding out what the error means... Here is a little function
that may help you out:

' get this for Win32Exception
Imports System.ComponentModel
Public Function GetWin32ErrorMsg(ByVal ErrorCode As Integer) As String
Dim ex As New Win32Exception(ErrorCode)
Return ex.Message
End Function

I have do have a FTP class I wrote using WinInet, if you would like to
look at it I will post it. The code is C#, but it is a fairly straight
forward conversion into VB.NET

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
Reality is bad enough, why should I tell the truth?
-- Patrick Sky
Nov 20 '05 #3
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:bv*************@ID-208219.news.uni-berlin.de...
* "Sjaakie Helderhorst" <pr**********@tell.you> scripsit:
### [ Class ]
Public Class Ftp

Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long


The declares are wrong. Replace the 'Long' with 'Int32', all parameters
with name 'h*' with 'IntPtr'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Thanks!
Nov 20 '05 #4
"Tom Shelton" <to*@mtogden.com> schreef in bericht
news:Ok**************@TK2MSFTNGP12.phx.gbl...
On 2004-02-05, Sjaakie Helderhorst <pr**********@tell.you> wrote:
Hi all,
I'm trying to create a class which handles FTP. Knowing little of classes I'm having some trouble making things work. Also having trouble finding the meaning of some error-codes. The code below results in a lastdllerror 6 (and no transfer)... can't find what this error means and how to solve it (yes I already tried google). Could someone please help me out?
< ... >
I have do have a FTP class I wrote using WinInet, if you would like to
look at it I will post it. The code is C#, but it is a fairly straight
forward conversion into VB.NET

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
Reality is bad enough, why should I tell the truth?
-- Patrick Sky


Thanks for your reply
I used an example I found on the Internet, apparently not very useful :S
Having trouble making it work but I'll try to figure it out myself first
before asking you guys again.
I'm an ASP (not .NET) programmer so I'm very interested in you FTP class, I
think it will help me alot in programming and understanding with dotNET.
Could you please e-mail me the class? (alter my e-mail address)

Thanks again!

Nov 20 '05 #5
Cor
Hallo Sjaakie,

Kudzu has been active in this newsgroup, I read in other newsgroup that this
is for Delphi very good stuff.

Indy now includes FTP, NNTP, SMTP, POP3 and more for .Net.

http://www.indyproject.org/indy.html

I hope this helps?

Cor
Nov 20 '05 #6
"Cor" <no*@non.com> schreef in bericht
news:O7**************@TK2MSFTNGP11.phx.gbl...
Hallo Sjaakie,

Kudzu has been active in this newsgroup, I read in other newsgroup that this is for Delphi very good stuff.

Indy now includes FTP, NNTP, SMTP, POP3 and more for .Net.
http://www.indyproject.org/indy.html
I hope this helps?

Cor


Thanks for the link... I'll have a look.
But there's something about 'finding it out yourself' :)
These 'prefab' projects are nice, but they teach me little about how things
are done in the code behind these components.
Nov 20 '05 #7
Cor
Hi Sjaakie,

But than you can better have a look also at this is managed code I thought

Microsoft webrequest
http://support.microsoft.com/default...b;EN-US;812409
I hope this helps a little bit?

These 'prefab' projects are nice, but they teach me little about how things are done in the code behind these components.

Nov 20 '05 #8
"Cor" <no*@non.com> schreef in bericht
news:%2******************@TK2MSFTNGP11.phx.gbl...
Hi Sjaakie,

But than you can better have a look also at this is managed code I thought

Microsoft webrequest
http://support.microsoft.com/default...b;EN-US;812409
I hope this helps a little bit?

These 'prefab' projects are nice, but they teach me little about how

things
are done in the code behind these components.


Thanks for your support, I have thing running over here.
Have a nice weekend!
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dan | last post by:
I have an app that uses the wininet.dll APIs to get web pages and to post to web forms. My problem is that some of my users systems will literally wait an hour before an Internet call to a site...
0
by: Gerry Abbott | last post by:
Hi All, Im trying to get som ftp functionality into my application, and have some code I sourced from this NG. I'm trying to tailor it for my needs, but need a better understanding of whats...
1
by: Sean Barnes | last post by:
Hello all, I am having a bit a problem with the InternetDial function in the wininet.dll. The problem is that despite passing in a null terminated string as the lpszConnectoid param to the...
1
by: Java Writer via .NET 247 | last post by:
Hey Mon!, This runs and gives me a 'iLen' of 4 but returns empty string. I am guessing this is the programmatic way to check Internet Explorer. {Tools}-{Internet Options)-(Settings...). Even...
3
by: Rich | last post by:
Greetings, I have a VB6 app that uses API's from wininet.dll for FTP- ing textfiles to and from Mainframe computers and doing directory searches on the mainframe from a windows desktop...
0
by: Sjaakie Helderhorst | last post by:
Hi all, I'm trying to create a class which handles FTP. Knowing little of classes I'm having some trouble making things work. Also having trouble finding the meaning of some error-codes. The code...
10
by: MLH | last post by:
My A97 runtime installations are sometimes paused during the install process prompting user with messages saying the files are in use. Generally, I tell them to click IGNORE. Although I haven't...
0
by: Nishini | last post by:
I am using "FtpFindFirstFile" function of wininet.dll in my application. I had the Declare statement for this function in my code but when I executed my applicaiton, it gave me an error saying...
0
by: Nishini | last post by:
I am using "FtpFindFirstFile" function of wininet.dll in my application. I had the Declare statement for this function in my code but when I executed my applicaiton, it gave me an error saying...
0
by: Axel | last post by:
Hello all, i've a problem with connection to a VPN Network through WinInet API. Scenario: 1 got 2 RAS-connections on my System: one for dialing into the internet via modem and the second for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.