473,467 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
9 3288
> 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
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
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
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
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

"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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
0
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
9
by: Martin Ortiz | last post by:
I want to use the Win32 API function : SendMessageToDescendants I want to use it in a VB.Net app, but I have a few questions..... 1) Can one use Win32 API functions in VB.Net 2) Is doing so a...
6
by: ian | last post by:
Hi, I keep resorting to com interop calls, for example I needed the location of the carot in a text box and I had to use a win32API call (GetCarotPos??) to do that. It's one example, I could give...
4
by: Vince Castellano | last post by:
Hello, I have a set of DLLs that implement different configurations of the same API. Consider them as first.dll, second.dll, and third.dll. They all share a common API, calling pattern, and have...
3
by: boris | last post by:
i am not able to understand how can i create google desktop api using only C and C++.should i also need to learn other languages or knowledge of my favourite c++ will do.I am confused.If it's...
12
by: MJK | last post by:
Hello everybody, I am almost a new C programmer and now I need to use SQL within my C codes. Does anybody have any idea about good examples on SQL using C? I have not any experience using SQL...
11
by: =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?= | last post by:
I've already got the code written but for some reason, when i click the button, nothing occurs. Here is the code. using System; using System.Collections.Generic; using System.ComponentModel;...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.