Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using wininet in windows CE 6.0 with VB 2005

163 views
Skip to first unread message

lsimoni

unread,
Dec 2, 2008, 10:43:02 AM12/2/08
to
I am trying to download a file from an FTP site to my device in a VB
application. When I get to the InternetOpen command, I get a
"NotSupportedException" and don't know what the problem is. wininte.dll is
present in the \windows directory, so it should be available.

Here's my code:

Imports System.Net.sockets
Imports System.Net
...

Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21 ' default for FTP
servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000 ' used for FTP
connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0 ' use registry
configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1 ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3 ' via named
proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 ' prevent
using java/script/INS
Const MAX_PATH = 260

Private Structure FILETIME
Dim dwLowDateTime As Long
Dim dwHighDateTime As Long
End Structure

Private Structure WIN32_FIND_DATA
Dim dwFileAttributes As Long
Dim ftCreationTime As FILETIME
Dim ftLastAccessTime As FILETIME
Dim ftLastWriteTime As FILETIME
Dim nFileSizeHigh As Long
Dim nFileSizeLow As Long
Dim dwReserved0 As Long
Dim dwReserved1 As Long
Dim cFileName As String
Dim cAlternate As String
End Structure
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByRef
hInet As Long) As Long
Public 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As
String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias
"FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal
lpszCurrentDirectory As String, ByVal lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias
"FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As
String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias
"FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As
String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias
"FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As
Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias
"FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String,
ByVal lpszNew As String) As Boolean
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
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias
"FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As
String, ByVal lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal
dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias
"InternetFindNextFileA" (ByVal hFind As Long, ByVal lpvFindData As
WIN32_FIND_DATA) As Long

Const PassiveConnection As Boolean = True
...
Dim i As Long = 1
Dim iCount As Long
Dim iK As Boolean
Dim scUserAgent As String = "VB OpenUrl"


i = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT,
vbNullString, vbNullString, 0)
iCount = InternetConnect(i,
"ftp.jpccontrols.com/Flash_Programming/Flash_Programs/BC_Group/",
INTERNET_DEFAULT_FTP_PORT, "Anonymous", "Guest", INTERNET_SERVICE_FTP, 0, 0)
iK = FtpGetFile(iCount, "ESU-2400.exe", "\Hard
Disk\ESU-2400\ESU-2400_FTP.exe", True, 1, 0, 0)

Chris Tacke, eMVP

unread,
Dec 2, 2008, 10:57:59 AM12/2/08
to
1. This is a Platform Builder group - you' far better off asking in the
compactframework group.
2. Windows CE uses unicode, not ASCII. Why are you aliasing to the "A"
functions (and then passing a unicode sting to boot)?


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:F262D3DE-C367-49C4...@microsoft.com...

lsimoni

unread,
Dec 2, 2008, 11:22:16 AM12/2/08
to
Thanks for your quick response. The only reason I posted it here was in case
I'm missing a component in the CE image that is causing the error.

As far as the Ascii reference, I had no idea that's what it did, thanks for
the input. I just tried InternetOpenW and it didn't work either...

I found the reference code in a sample somewhere, figured if it worked for
them it would work for me. I've also tried the OpenNETCF, but couldn't find
a straight example of what to do once it was included in the project. There
are lots of C# examples, but not much for VB.

Paul G. Tobey [eMVP]

unread,
Dec 2, 2008, 11:42:35 AM12/2/08
to
As Chris pointed out, you don't want FunctionNameA; you want FunctionNameW.
However, even with those changes, I get what you're seeing also. Not sure
why, either. A C++ program that does the same operation works fine. I've
verified the exports from wininet.dll. I've also tried building the program
for .NET CF 2.0, rather than .NET CF 3.5, which is what's built into my
device.

Paul T.

"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:F262D3DE-C367-49C4...@microsoft.com...

lsimoni

unread,
Dec 2, 2008, 11:52:01 AM12/2/08
to
You guys are the masters, and from what you're saying I'm doing everything
right and it still doesn't work. Does that mean I'm SOL? Is there anything
else I can do? All I need is to be able to download through FTP. Maybe
there's a better way?

Chris Tacke, eMVP

unread,
Dec 2, 2008, 11:59:26 AM12/2/08
to
There certainly is a better way. I'd use the library found here:
http://community.opennetcf.com/forums/p/10502/64582.aspx#64582

I wrote it right off the RFC using plain sockets. The object model is
really simple and should be self explanatory in any language. I dislike the
version in the SDF because it's modeleld after the Microsoft stream-based
version which is nothing but confusing in my mind.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:DEA9C27F-CAFE-4E3C...@microsoft.com...

Paul G. Tobey [eMVP]

unread,
Dec 2, 2008, 12:07:45 PM12/2/08
to
No, not everything, just everything that jumps out at us. I'm sure there's
an error there.

Ah, here it is. You've got a bunch of stuff declared 'Long'. Wrong. C++
'long' == VB.NET 'Int' or, specifically, 'Int32'. Long is a 64-bit integer.
Here's what I got to work:

-----

Dim i As Int32 = 1

Dim iCount As Int32

Dim iK As Boolean

Dim scUserAgent As String = "VB OpenUrl"

i = InternetOpenW(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString,
vbNullString, 0)

iCount = InternetConnectW(i, "<servername>", INTERNET_DEFAULT_FTP_PORT,
"<username>", "<password>", INTERNET_SERVICE_FTP, 0, 0)

iK = FtpGetFileW(iCount, "\test.txt", "\flash\text.txt", True, 1, 0, 0)

InternetCloseHandle(iCount)

InternetCloseHandle(i)

....

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByRef hInet

As Int32) As Int32

Public Declare Function InternetConnectW Lib "wininet.dll" (ByVal
hInternetSession As Int32, ByVal sServerName As String, ByVal nServerPort As

Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal

lService As Int32, ByVal lFlags As Int32, ByVal lContext As Int32) As Int32

Private Declare Function InternetOpenW Lib "wininet.dll" (ByVal sAgent As
String, ByVal lAccessType As Int32, ByVal sProxyName As String, ByVal
sProxyBypass As String, ByVal lFlags As Int32) As Int32

Private Declare Function FtpGetFileW Lib "wininet.dll" (ByVal hConnect As
Int32, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal
fFailIfExists As Int32, ByVal dwFlagsAndAttributes As Int32, ByVal dwFlags
As Int32, ByRef dwContext As Int32) As Boolean

-----

Paul T.

"lsimoni" <lsi...@discussions.microsoft.com> wrote in message

news:DEA9C27F-CAFE-4E3C...@microsoft.com...

lsimoni

unread,
Dec 2, 2008, 1:01:01 PM12/2/08
to
Thank you both very much! It works great. The samples looked so simple and
yet they wouldn't work for me, very frustrating. I've lost a couple of days
just trying to make sense of it and investigate alternative solutions.

I know just enough about vb.net to be dangerous. VB6 was much more
forgiving and easier to get by with.

I'll remember the C++ long translation, as I'm sure this isn't the last API
that I need to call.

"Paul G. Tobey [eMVP]" wrote:

> No, not everything, just everything that jumps out at us. I'm sure there's
> an error there.
>
> Ah, here it is. You've got a bunch of stuff declared 'Long'. Wrong. C++
> 'long' == VB.NET 'Int' or, specifically, 'Int32'. Long is a 64-bit integer.
> Here's what I got to work:
>
> -----
>
> Dim i As Int32 = 1
>
> Dim iCount As Int32
>
> Dim iK As Boolean
>
> Dim scUserAgent As String = "VB OpenUrl"
>
> i = InternetOpenW(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString,
> vbNullString, 0)
>
> iCount = InternetConnectW(i, "<servername>", INTERNET_DEFAULT_FTP_PORT,
> "<username>", "<password>", INTERNET_SERVICE_FTP, 0, 0)
>
> iK = FtpGetFileW(iCount, "\test.txt", "\flash\text.txt", True, 1, 0, 0)
>
> InternetCloseHandle(iCount)
>
> InternetCloseHandle(i)
>

> .....

0 new messages