By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

Using C++ API's in vb.net?

P: n/a
Ron
Hello,

Is it required to use

Imports System.Runtime.InteropServices

to run C++ API code? I ask because I thought I read
somewhere that this was required. If it is not required
would it interfere if I added it? I experimented with a
simple API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

which ran fine with/without the Imports statement above.
I am migrating a vb6 project to vb.net, and this project
used a lot of API's from wininet.dll, specifically the
following Ftp API's (which I understand Ftp will be
integrated into VS2005) for interfacing between a windows
workstations and a mainframe computer. Any suggestions
are appreciated on using these API's in vb.net for my
migration project.
-------------------------------------------------------
Public Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal _
lpszLocalFile As String, ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
-------------------------------------------------------

Public Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public 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
--------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dll" _
Alias "FtpCommandA" (ByVal hConnect As Long, ByVal _
fExpectResponse As Boolean, ByVal dwFlags As Long, _
ByVal lpszCommand As String, ByVal dwContext As Long, _
ByRef response_handle As Long) As Boolean
--------------------------------------------------------

Thanks,
Ron
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
> Hello,

Is it required to use

Imports System.Runtime.InteropServices

to run C++ API code? I ask because I thought I read
somewhere that this was required. If it is not required
would it interfere if I added it? I experimented with a
simple API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

which ran fine with/without the Imports statement above.
I am migrating a vb6 project to vb.net, and this project
used a lot of API's from wininet.dll, specifically the
following Ftp API's (which I understand Ftp will be
integrated into VS2005) for interfacing between a windows
workstations and a mainframe computer. Any suggestions
are appreciated on using these API's in vb.net for my
migration project.
-------------------------------------------------------
Public Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal _
lpszLocalFile As String, ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
-------------------------------------------------------

Public Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public 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
--------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dll" _
Alias "FtpCommandA" (ByVal hConnect As Long, ByVal _
fExpectResponse As Boolean, ByVal dwFlags As Long, _
ByVal lpszCommand As String, ByVal dwContext As Long, _
ByRef response_handle As Long) As Boolean
--------------------------------------------------------

Thanks,
Ron


Ron --

I just finished converting (upgrading ?) a VB6 project to VB.Net that
uses several WinInet functions. There were a few problems with
syntax but the project is now running 24/7 as a service on our
server without any problems. Here's a few suggestions.

1. You can easily use the declares you have listed if you
change all declarations of "Long" to "Integer".

2. After opening a connection to the server I had to use

Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean

to set the current directory instead of using a path name. Using
a path just didn't seem to work.

3. I couldn't find a way to use wildcards in the file names
so I wrote some validation into my code that validated the
file names before processing the files.

If this is a one-time conversion then just use the WinInet
API and don't worry about using the .Net framework. The
framework is not intuitive (note how you must declare fixed-length
strings in the WIN32_FIND_DATA structure) and you'll have
to spend some time converting your code over. If you're moving from
VB6 to VB.Net then search Google for FTP .Net and you'll
get several examples of using the .Net framework for
FTP. Here's the declarations I used for my project in case
you still want to use WinInet.

Private Declare Function InternetCloseHandle _
Lib "wininet.dll" _
(ByVal HINet As Integer) As Integer
Private Declare Function InternetOpen _
Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, _
ByVal lAccessType As Integer, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Integer) As Integer
Private Declare Function InternetConnect _
Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Integer, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Integer, _
ByVal lFlags As Integer, _
ByVal lContext As Integer) As Integer
Private Declare Function FtpGetFile _
Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
Private Declare Function FtpPutFile _
Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Integer, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean

Private Declare Function FtpDeleteFile _
Lib "wininet.dll" Alias "FtpDeleteFileA" _
(ByVal hFtpSession As Integer, _
ByVal lpszFileName As String) As Integer

Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean

Private Declare Auto Function FtpFindFirstFile _
Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Integer, _
ByVal lpszSearchFile As String, _
ByRef lpFindFileData As WIN32_FIND_DATA, _
ByVal dwFlags As Integer, _
ByVal dwContent As Integer) As Integer

Private Declare Auto Function InternetFindNextFile _
Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Integer, _
ByRef lpvFindData As WIN32_FIND_DATA) As Integer

Public Structure FILETIME
Public dwLowDateTime As Integer
Public dwHighDateTime As Integer
End Structure

Public Structure WIN32_FIND_DATA
Public dwFileAttributes As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTime As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer

<System.Runtime.InteropServices.MarshalAs(System.R untime.InteropServices.UnmanagedType.ByV
alTStr, SizeConst:=260)> Public cFileName As String

<System.Runtime.InteropServices.MarshalAs(System.R untime.InteropServices.UnmanagedType.ByV
alTStr, SizeConst:=14)> Public cAlternate As String
End Structure

HTH,

Jim Edgar
Nov 21 '05 #2

P: n/a
In article <0c****************************@phx.gbl>, Ron wrote:
Hello,

Is it required to use

Imports System.Runtime.InteropServices

to run C++ API code? I ask because I thought I read
somewhere that this was required. If it is not required
It's never "required", but it can make things convienent if you intend
to use any of the attributes or classes in that namespace. If you don't
import it, then you have to use the fully qualified name.
would it interfere if I added it? I experimented with a
simple API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

It wouldn't be required at all for this one, because you aren't using
any attributes. However, your declare is wrong for VB.NET...

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Integer)

Datatype sizes have changed in VB.NET. Long is a 64-bit value, not
32-bit as in VB.CLASSIC.
which ran fine with/without the Imports statement above.
I am migrating a vb6 project to vb.net, and this project
used a lot of API's from wininet.dll, specifically the
following Ftp API's (which I understand Ftp will be
integrated into VS2005) for interfacing between a windows
workstations and a mainframe computer. Any suggestions
are appreciated on using these API's in vb.net for my
migration project.
-------------------------------------------------------
Public Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal _
lpszLocalFile As String, ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
-------------------------------------------------------

Public Declare Auto Function FtpPutFile Lib "wininet.dll" _
(ByVal hFtpSession As IntPtr, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
--------------------------------------------------------
Public Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public Declare Auto Function FtpDeleteFile Lib "wininet.dll" _
(ByVal hFtpSession As IntPtr, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public 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
--------------------------------------------------------
Public Declare Auto Function FtpGetFile Lib "wininet.dll" _
(ByVal hFtpSession As IntPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
--------------------------------------------------------
Public Declare Function FtpCommand Lib "wininet.dll" _
Alias "FtpCommandA" (ByVal hConnect As Long, ByVal _
fExpectResponse As Boolean, ByVal dwFlags As Long, _
ByVal lpszCommand As String, ByVal dwContext As Long, _
ByRef response_handle As Long) As Boolean
--------------------------------------------------------


Public Declare Auto Function FtpCommand Lib "wininet.dll" _
(ByVal hConnect As IntPtr, _
ByVal fExpectResponse As Boolean, _
ByVal dwFlags As Integer, _
ByVal lpszCommand As String, _
ByVal dwContext As Integer, _
ByRef phFtpCommand As IntPtr) As Boolean

HTH
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 9 Days, 22 Hours, 23 Minutes, 45 Seconds
Nov 21 '05 #3

P: n/a
Ron
Thanks very much for all the info. I do still have to
move on to vb.net and wininet.dll. And I was going to ask
about WIN32_FIND_DATA next :). You answered several of my
question (as well as Tom). I think my best bet is to
search google as you point out, on FTP .Net. I still have
a bunch of other APIs as you have listed that I need to
convert.

Do you know if VS2005 has the full implementation for
wininet.dll and the like or will we still have to declare
a few API's?

Thanks again,
Ron
-----Original Message-----
Hello,

Is it required to use

Imports System.Runtime.InteropServices

to run C++ API code? I ask because I thought I read
somewhere that this was required. If it is not required
would it interfere if I added it? I experimented with a
simple API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

which ran fine with/without the Imports statement above.
I am migrating a vb6 project to vb.net, and this project
used a lot of API's from wininet.dll, specifically the
following Ftp API's (which I understand Ftp will be
integrated into VS2005) for interfacing between a windows workstations and a mainframe computer. Any suggestions
are appreciated on using these API's in vb.net for my
migration project.
-------------------------------------------------------
Public Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal _
lpszLocalFile As String, ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean -------------------------------------------------------

Public Declare Function FtpDeleteFile Lib "wininet.dll" _ Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public 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 --------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dll" _
Alias "FtpCommandA" (ByVal hConnect As Long, ByVal _
fExpectResponse As Boolean, ByVal dwFlags As Long, _
ByVal lpszCommand As String, ByVal dwContext As Long, _
ByRef response_handle As Long) As Boolean
--------------------------------------------------------

Thanks,
Ron
Ron --

I just finished converting (upgrading ?) a VB6 project to

VB.Net thatuses several WinInet functions. There were a few problems withsyntax but the project is now running 24/7 as a service on ourserver without any problems. Here's a few suggestions.

1. You can easily use the declares you have listed if you
change all declarations of "Long" to "Integer".

2. After opening a connection to the server I had to use

Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean

to set the current directory instead of using a path name. Usinga path just didn't seem to work.

3. I couldn't find a way to use wildcards in the file namesso I wrote some validation into my code that validated the
file names before processing the files.

If this is a one-time conversion then just use the WinInet
API and don't worry about using the .Net framework. The
framework is not intuitive (note how you must declare fixed-lengthstrings in the WIN32_FIND_DATA structure) and you'll have
to spend some time converting your code over. If you're moving fromVB6 to VB.Net then search Google for FTP .Net and you'll
get several examples of using the .Net framework for
FTP. Here's the declarations I used for my project in caseyou still want to use WinInet.

Private Declare Function InternetCloseHandle _
Lib "wininet.dll" _
(ByVal HINet As Integer) As Integer Private Declare Function InternetOpen _
Lib "wininet.dll" Alias "InternetOpenA" _ (ByVal sAgent As String, _
ByVal lAccessType As Integer, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Integer) As Integer Private Declare Function InternetConnect _
Lib "wininet.dll" Alias "InternetConnectA" _ (ByVal hInternetSession As Integer, _ ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Integer, _
ByVal lFlags As Integer, _
ByVal lContext As Integer) As Integer Private Declare Function FtpGetFile _
Lib "wininet.dll" Alias "FtpGetFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _ ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean Private Declare Function FtpPutFile _
Lib "wininet.dll" Alias "FtpPutFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
Private Declare Function FtpDeleteFile _
Lib "wininet.dll" Alias "FtpDeleteFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszFileName As String) As Integer
Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _ (ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean
Private Declare Auto Function FtpFindFirstFile _
Lib "wininet.dll" Alias "FtpFindFirstFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszSearchFile As String, _
ByRef lpFindFileData As WIN32_FIND_DATA, _ ByVal dwFlags As Integer, _
ByVal dwContent As Integer) As Integer
Private Declare Auto Function InternetFindNextFile _
Lib "wininet.dll" Alias "InternetFindNextFileA" _ (ByVal hFind As Integer, _
ByRef lpvFindData As WIN32_FIND_DATA) As Integer
Public Structure FILETIME
Public dwLowDateTime As Integer
Public dwHighDateTime As Integer
End Structure

Public Structure WIN32_FIND_DATA
Public dwFileAttributes As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTime As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer

<System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=260)> Public cFileName As String

<System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=14)> Public cAlternate As String
End Structure

HTH,

Jim Edgar
.

Nov 21 '05 #4

P: n/a
Ron
Thanks very much for all the info. Would I be correct to
generalize that if a var in the API Declares is preceded
by an h that it will be an IntPtr? I have used IntPtr's
in enum structures in C#, kind of like a hash table (note:
I have way less experience in C# than I do VB/VB.Net). If
I search on FTP .Net will that have enough info for
converting all the com API calls to .Net?

Thanks,
Ron

-----Original Message-----
In article <0c****************************@phx.gbl>, Ron wrote:
Hello,

Is it required to use

Imports System.Runtime.InteropServices

to run C++ API code? I ask because I thought I read
somewhere that this was required. If it is not required
It's never "required", but it can make things convienent if you intendto use any of the attributes or classes in that namespace. If you don'timport it, then you have to use the fully qualified name.
would it interfere if I added it? I experimented with
a simple API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)


It wouldn't be required at all for this one, because you

aren't usingany attributes. However, your declare is wrong for VB.NET...
Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Integer)

Datatype sizes have changed in VB.NET. Long is a 64-bit value, not32-bit as in VB.CLASSIC.
which ran fine with/without the Imports statement above. I am migrating a vb6 project to vb.net, and this project used a lot of API's from wininet.dll, specifically the
following Ftp API's (which I understand Ftp will be
integrated into VS2005) for interfacing between a windows workstations and a mainframe computer. Any suggestions
are appreciated on using these API's in vb.net for my
migration project.
-------------------------------------------------------
Public Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal _
lpszLocalFile As String, ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean -------------------------------------------------------

Public Declare Auto Function FtpPutFile Lib "wininet.dll"

_ (ByVal hFtpSession As IntPtr, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
--------------------------------------------------------
Public Declare Function FtpDeleteFile Lib "wininet.dll" _ Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public Declare Auto Function FtpDeleteFile

Lib "wininet.dll" _ (ByVal hFtpSession As IntPtr, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public 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 --------------------------------------------------------
Public Declare Auto Function FtpGetFile Lib "wininet.dll"

_ (ByVal hFtpSession As IntPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
--------------------------------------------------------
Public Declare Function FtpCommand Lib "wininet.dll" _
Alias "FtpCommandA" (ByVal hConnect As Long, ByVal _
fExpectResponse As Boolean, ByVal dwFlags As Long, _
ByVal lpszCommand As String, ByVal dwContext As Long, _
ByRef response_handle As Long) As Boolean
--------------------------------------------------------
Public Declare Auto Function FtpCommand Lib "wininet.dll"

_ (ByVal hConnect As IntPtr, _
ByVal fExpectResponse As Boolean, _
ByVal dwFlags As Integer, _
ByVal lpszCommand As String, _
ByVal dwContext As Integer, _
ByRef phFtpCommand As IntPtr) As Boolean

HTH
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP ProfessionalOS Version: 5.1.2600 Service Pack 2 Build 2600System Up Time: 9 Days, 22 Hours, 23 Minutes, 45 Seconds.

Nov 21 '05 #5

P: n/a
Ron
One more question if I may, are all the constants below
(from my vb6 app) still the same?

Public Const MAX_PATH = 260

Public Const NO_ERROR = 0
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_OFFLINE = &H1000
Public Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Public Const MAXDWORD = &HFFFFFFFF

Public Const INTERNET_FLAG_PASSIVE = &H8000000
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Const INTERNET_OPTION_CONNECT_TIMEOUT = 2
Public Const INTERNET_OPTION_SEND_TIMEOUT = 5
Public Const INTERNET_OPTION_RECEIVE_TIMEOUT = 6
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_INVALID_PORT_NUMBER = 0
Public Const INTERNET_SERVICE_FTP = 1
Public Const INTERNET_SERVICE_GOPHER = &O2
Public Const INTERNET_SERVICE_HTTP = 3
Public Const INTERNET_OPEN_TYPE_DIRECT = 1
Public Const INTERNET_OPEN_TYPE_PROXY = 3
Public Const INTERNET_DEFAULT_FTP_PORT = 21
Public Const INTERNET_DEFAULT_GOPHER_PORT = 70
Public Const INTERNET_DEFAULT_HTTP_PORT = 80
Public Const INTERNET_DEFAULT_HTTPS_PORT = 443
Public Const INTERNET_DEFAULT_SOCKS_PORT = 1080

Public Const FTP_TRANSFER_TYPE_BINARY = &H2
Public Const FTP_TRANSFER_TYPE_ASCII = &H1

Public Const ERROR_NO_MORE_FILES = 18

Thanks,
Ron
-----Original Message-----
Hello,

Is it required to use

Imports System.Runtime.InteropServices

to run C++ API code? I ask because I thought I read
somewhere that this was required. If it is not required
would it interfere if I added it? I experimented with a
simple API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

which ran fine with/without the Imports statement above.
I am migrating a vb6 project to vb.net, and this project
used a lot of API's from wininet.dll, specifically the
following Ftp API's (which I understand Ftp will be
integrated into VS2005) for interfacing between a windows workstations and a mainframe computer. Any suggestions
are appreciated on using these API's in vb.net for my
migration project.
-------------------------------------------------------
Public Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal _
lpszLocalFile As String, ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean -------------------------------------------------------

Public Declare Function FtpDeleteFile Lib "wininet.dll" _ Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public 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 --------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dll" _
Alias "FtpCommandA" (ByVal hConnect As Long, ByVal _
fExpectResponse As Boolean, ByVal dwFlags As Long, _
ByVal lpszCommand As String, ByVal dwContext As Long, _
ByRef response_handle As Long) As Boolean
--------------------------------------------------------

Thanks,
Ron
Ron --

I just finished converting (upgrading ?) a VB6 project to

VB.Net thatuses several WinInet functions. There were a few problems withsyntax but the project is now running 24/7 as a service on ourserver without any problems. Here's a few suggestions.

1. You can easily use the declares you have listed if you
change all declarations of "Long" to "Integer".

2. After opening a connection to the server I had to use

Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean

to set the current directory instead of using a path name. Usinga path just didn't seem to work.

3. I couldn't find a way to use wildcards in the file namesso I wrote some validation into my code that validated the
file names before processing the files.

If this is a one-time conversion then just use the WinInet
API and don't worry about using the .Net framework. The
framework is not intuitive (note how you must declare fixed-lengthstrings in the WIN32_FIND_DATA structure) and you'll have
to spend some time converting your code over. If you're moving fromVB6 to VB.Net then search Google for FTP .Net and you'll
get several examples of using the .Net framework for
FTP. Here's the declarations I used for my project in caseyou still want to use WinInet.

Private Declare Function InternetCloseHandle _
Lib "wininet.dll" _
(ByVal HINet As Integer) As Integer Private Declare Function InternetOpen _
Lib "wininet.dll" Alias "InternetOpenA" _ (ByVal sAgent As String, _
ByVal lAccessType As Integer, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Integer) As Integer Private Declare Function InternetConnect _
Lib "wininet.dll" Alias "InternetConnectA" _ (ByVal hInternetSession As Integer, _ ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Integer, _
ByVal lFlags As Integer, _
ByVal lContext As Integer) As Integer Private Declare Function FtpGetFile _
Lib "wininet.dll" Alias "FtpGetFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _ ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean Private Declare Function FtpPutFile _
Lib "wininet.dll" Alias "FtpPutFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
Private Declare Function FtpDeleteFile _
Lib "wininet.dll" Alias "FtpDeleteFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszFileName As String) As Integer
Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _ (ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean
Private Declare Auto Function FtpFindFirstFile _
Lib "wininet.dll" Alias "FtpFindFirstFileA" _ (ByVal hFtpSession As Integer, _
ByVal lpszSearchFile As String, _
ByRef lpFindFileData As WIN32_FIND_DATA, _ ByVal dwFlags As Integer, _
ByVal dwContent As Integer) As Integer
Private Declare Auto Function InternetFindNextFile _
Lib "wininet.dll" Alias "InternetFindNextFileA" _ (ByVal hFind As Integer, _
ByRef lpvFindData As WIN32_FIND_DATA) As Integer
Public Structure FILETIME
Public dwLowDateTime As Integer
Public dwHighDateTime As Integer
End Structure

Public Structure WIN32_FIND_DATA
Public dwFileAttributes As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTime As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer

<System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=260)> Public cFileName As String

<System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=14)> Public cAlternate As String
End Structure

HTH,

Jim Edgar
.

Nov 21 '05 #6

P: n/a

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
Thanks very much for all the info. I do still have to
move on to vb.net and wininet.dll. And I was going to ask
about WIN32_FIND_DATA next :). You answered several of my
question (as well as Tom). I think my best bet is to
search google as you point out, on FTP .Net. I still have
a bunch of other APIs as you have listed that I need to
convert.

Do you know if VS2005 has the full implementation for
wininet.dll and the like or will we still have to declare
a few API's?

Thanks again,
Ron

<snip>

If you are moving on to .net then you might take a look at the
following: http://www.freevbcode.com/ShowCode.asp?ID=4655
It's an FTP project that you can use as the framework for your
own .Net project. I found it quicker to use the existing VB6
code for my project but if I were to write a serious FTP project
for .Net then I'd refer to this example.

Jim Edgar
Nov 21 '05 #7

P: n/a
> One more question if I may, are all the constants below
(from my vb6 app) still the same?

Public Const MAX_PATH = 260

Public Const NO_ERROR = 0
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_OFFLINE = &H1000
Public Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Public Const MAXDWORD = &HFFFFFFFF

Public Const INTERNET_FLAG_PASSIVE = &H8000000
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Const INTERNET_OPTION_CONNECT_TIMEOUT = 2
Public Const INTERNET_OPTION_SEND_TIMEOUT = 5
Public Const INTERNET_OPTION_RECEIVE_TIMEOUT = 6
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_INVALID_PORT_NUMBER = 0
Public Const INTERNET_SERVICE_FTP = 1
Public Const INTERNET_SERVICE_GOPHER = &O2
Public Const INTERNET_SERVICE_HTTP = 3
Public Const INTERNET_OPEN_TYPE_DIRECT = 1
Public Const INTERNET_OPEN_TYPE_PROXY = 3
Public Const INTERNET_DEFAULT_FTP_PORT = 21
Public Const INTERNET_DEFAULT_GOPHER_PORT = 70
Public Const INTERNET_DEFAULT_HTTP_PORT = 80
Public Const INTERNET_DEFAULT_HTTPS_PORT = 443
Public Const INTERNET_DEFAULT_SOCKS_PORT = 1080

Public Const FTP_TRANSFER_TYPE_BINARY = &H2
Public Const FTP_TRANSFER_TYPE_ASCII = &H1

Public Const ERROR_NO_MORE_FILES = 18

Thanks,
Ron


The values remain the same but I'm not sure if .Net requires you
to explicitly declare them as Integers, ie:

Public Const NO_ERROR As Integer = 0

Jim Edgar


Nov 21 '05 #8

P: n/a
Ron
Yes. I had to as As Integer to the constants that didn't
have the As clause.

Well, I downloaded the example you suggested and tried to
run it. The Main form is not visible, and I even added
Me.Visible = True. I placed it in a virtual dir of my web
server. Any suggestions if I need to do anything else?
-----Original Message-----

"Ron" <an*******@discussions.microsoft.com> wrote in messagenews:0d****************************@phx.gbl...
Thanks very much for all the info. I do still have to
move on to vb.net and wininet.dll. And I was going to ask about WIN32_FIND_DATA next :). You answered several of my question (as well as Tom). I think my best bet is to
search google as you point out, on FTP .Net. I still have a bunch of other APIs as you have listed that I need to
convert.

Do you know if VS2005 has the full implementation for
wininet.dll and the like or will we still have to declare a few API's?

Thanks again,
Ron
<snip>

If you are moving on to .net then you might take a look

at thefollowing: http://www.freevbcode.com/ShowCode.asp?ID=4655
It's an FTP project that you can use as the framework for yourown .Net project. I found it quicker to use the existing VB6code for my project but if I were to write a serious FTP projectfor .Net then I'd refer to this example.

Jim Edgar
.

Nov 21 '05 #9

P: n/a
Ron
OK. I clicked on the icon in the tray. Cool. Does this
need to be in a web server dir?
-----Original Message-----
Yes. I had to as As Integer to the constants that didn't
have the As clause.

Well, I downloaded the example you suggested and tried to
run it. The Main form is not visible, and I even added
Me.Visible = True. I placed it in a virtual dir of my webserver. Any suggestions if I need to do anything else?
-----Original Message-----

"Ron" <an*******@discussions.microsoft.com> wrote inmessage
news:0d****************************@phx.gbl...
Thanks very much for all the info. I do still have to
move on to vb.net and wininet.dll. And I was going toask about WIN32_FIND_DATA next :). You answered several
ofmy question (as well as Tom). I think my best bet is to
search google as you point out, on FTP .Net. I stillhave a bunch of other APIs as you have listed that I need to
convert.

Do you know if VS2005 has the full implementation for
wininet.dll and the like or will we still have todeclare a few API's?

Thanks again,
Ron
<snip>

If you are moving on to .net then you might take a look

at the
following: http://www.freevbcode.com/ShowCode.asp?ID=4655
It's an FTP project that you can use as the framework

foryour
own .Net project. I found it quicker to use the
existingVB6
code for my project but if I were to write a serious FTP

project
for .Net then I'd refer to this example.

Jim Edgar
.

.

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.