473,732 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ 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.dl l" _
Alias "FtpPutFile A" (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.dl l" _
Alias "FtpDeleteFileA " (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public Declare Function FtpGetFile Lib "wininet.dl l" _
Alias "FtpGetFile A" (ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, ByVal lpszNewFile _
As String, ByVal fFailIfExists As Boolean, ByVal _
dwFlagsAndAttri butes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
--------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dl l" _
Alias "FtpCommand A" (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 3315
> 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.dl l" _
Alias "FtpPutFile A" (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.dl l" _
Alias "FtpDeleteFileA " (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public Declare Function FtpGetFile Lib "wininet.dl l" _
Alias "FtpGetFile A" (ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, ByVal lpszNewFile _
As String, ByVal fFailIfExists As Boolean, ByVal _
dwFlagsAndAttri butes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
--------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dl l" _
Alias "FtpCommand A" (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 FtpSetCurrentDi rectory _
Lib "wininet.dl l" Alias "FtpSetCurrentD irectoryA" _
(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 InternetCloseHa ndle _
Lib "wininet.dl l" _
(ByVal HINet As Integer) As Integer
Private Declare Function InternetOpen _
Lib "wininet.dl l" Alias "InternetOp enA" _
(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.dl l" Alias "InternetConnec tA" _
(ByVal hInternetSessio n 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.dl l" Alias "FtpGetFile A" _
(ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttri butes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
Private Declare Function FtpPutFile _
Lib "wininet.dl l" Alias "FtpPutFile A" _
(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.dl l" Alias "FtpDeleteFileA " _
(ByVal hFtpSession As Integer, _
ByVal lpszFileName As String) As Integer

Private Declare Function FtpSetCurrentDi rectory _
Lib "wininet.dl l" Alias "FtpSetCurrentD irectoryA" _
(ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean

Private Declare Auto Function FtpFindFirstFil e _
Lib "wininet.dl l" Alias "FtpFindFirstFi leA" _
(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 InternetFindNex tFile _
Lib "wininet.dl l" Alias "InternetFindNe xtFileA" _
(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 dwFileAttribute s As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTim e As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer

<System.Runtime .InteropService s.MarshalAs(Sys tem.Runtime.Int eropServices.Un managedType.ByV
alTStr, SizeConst:=260) > Public cFileName As String

<System.Runtime .InteropService s.MarshalAs(Sys tem.Runtime.Int eropServices.Un managedType.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.dl l" _
Alias "FtpPutFile A" (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.dl l" _
(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.dl l" _
Alias "FtpDeleteFileA " (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public Declare Auto Function FtpDeleteFile Lib "wininet.dl l" _
(ByVal hFtpSession As IntPtr, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public Declare Function FtpGetFile Lib "wininet.dl l" _
Alias "FtpGetFile A" (ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, ByVal lpszNewFile _
As String, ByVal fFailIfExists As Boolean, ByVal _
dwFlagsAndAttri butes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
--------------------------------------------------------
Public Declare Auto Function FtpGetFile Lib "wininet.dl l" _
(ByVal hFtpSession As IntPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttri butes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
--------------------------------------------------------
Public Declare Function FtpCommand Lib "wininet.dl l" _
Alias "FtpCommand A" (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.dl l" _
(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.dl l" _
Alias "FtpPutFile A" (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.dl l" _ Alias "FtpDeleteFileA " (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public Declare Function FtpGetFile Lib "wininet.dl l" _
Alias "FtpGetFile A" (ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, ByVal lpszNewFile _
As String, ByVal fFailIfExists As Boolean, ByVal _
dwFlagsAndAttri butes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean --------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dl l" _
Alias "FtpCommand A" (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 FtpSetCurrentDi rectory _
Lib "wininet.dl l" Alias "FtpSetCurrentD irectoryA" _
(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 InternetCloseHa ndle _
Lib "wininet.dl l" _
(ByVal HINet As Integer) As Integer Private Declare Function InternetOpen _
Lib "wininet.dl l" Alias "InternetOp enA" _ (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.dl l" Alias "InternetConnec tA" _ (ByVal hInternetSessio n 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.dl l" Alias "FtpGetFile A" _ (ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttri butes As Integer, _ ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean Private Declare Function FtpPutFile _
Lib "wininet.dl l" Alias "FtpPutFile A" _ (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.dl l" Alias "FtpDeleteFileA " _ (ByVal hFtpSession As Integer, _
ByVal lpszFileName As String) As Integer
Private Declare Function FtpSetCurrentDi rectory _
Lib "wininet.dl l" Alias "FtpSetCurrentD irectoryA" _ (ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean
Private Declare Auto Function FtpFindFirstFil e _
Lib "wininet.dl l" Alias "FtpFindFirstFi leA" _ (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 InternetFindNex tFile _
Lib "wininet.dl l" Alias "InternetFindNe xtFileA" _ (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 dwFileAttribute s As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTim e As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer

<System.Runtim e.InteropServic es.MarshalAs (System.Runtime .InteropService s.UnmanagedType .ByValTStr, SizeConst:=260) > Public cFileName As String

<System.Runtim e.InteropServic es.MarshalAs (System.Runtime .InteropService s.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.dl l" _
Alias "FtpPutFile A" (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.dl l"

_ (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.dl l" _ Alias "FtpDeleteFileA " (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public Declare Auto Function FtpDeleteFile

Lib "wininet.dl l" _ (ByVal hFtpSession As IntPtr, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------
Public Declare Function FtpGetFile Lib "wininet.dl l" _
Alias "FtpGetFile A" (ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, ByVal lpszNewFile _
As String, ByVal fFailIfExists As Boolean, ByVal _
dwFlagsAndAttri butes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean --------------------------------------------------------
Public Declare Auto Function FtpGetFile Lib "wininet.dl l"

_ (ByVal hFtpSession As IntPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttri butes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean
--------------------------------------------------------
Public Declare Function FtpCommand Lib "wininet.dl l" _
Alias "FtpCommand A" (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.dl l"

_ (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_P ASSIVE = &H8000000
Public Const INTERNET_FLAG_R ELOAD = &H80000000
Public Const INTERNET_OPTION _CONNECT_TIMEOU T = 2
Public Const INTERNET_OPTION _SEND_TIMEOUT = 5
Public Const INTERNET_OPTION _RECEIVE_TIMEOU T = 6
Public Const INTERNET_OPEN_T YPE_PRECONFIG = 0
Public Const INTERNET_INVALI D_PORT_NUMBER = 0
Public Const INTERNET_SERVIC E_FTP = 1
Public Const INTERNET_SERVIC E_GOPHER = &O2
Public Const INTERNET_SERVIC E_HTTP = 3
Public Const INTERNET_OPEN_T YPE_DIRECT = 1
Public Const INTERNET_OPEN_T YPE_PROXY = 3
Public Const INTERNET_DEFAUL T_FTP_PORT = 21
Public Const INTERNET_DEFAUL T_GOPHER_PORT = 70
Public Const INTERNET_DEFAUL T_HTTP_PORT = 80
Public Const INTERNET_DEFAUL T_HTTPS_PORT = 443
Public Const INTERNET_DEFAUL T_SOCKS_PORT = 1080

Public Const FTP_TRANSFER_TY PE_BINARY = &H2
Public Const FTP_TRANSFER_TY PE_ASCII = &H1

Public Const ERROR_NO_MORE_F ILES = 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.dl l" _
Alias "FtpPutFile A" (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.dl l" _ Alias "FtpDeleteFileA " (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
--------------------------------------------------------

Public Declare Function FtpGetFile Lib "wininet.dl l" _
Alias "FtpGetFile A" (ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, ByVal lpszNewFile _
As String, ByVal fFailIfExists As Boolean, ByVal _
dwFlagsAndAttri butes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean --------------------------------------------------------

Public Declare Function FtpCommand Lib "wininet.dl l" _
Alias "FtpCommand A" (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 FtpSetCurrentDi rectory _
Lib "wininet.dl l" Alias "FtpSetCurrentD irectoryA" _
(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 InternetCloseHa ndle _
Lib "wininet.dl l" _
(ByVal HINet As Integer) As Integer Private Declare Function InternetOpen _
Lib "wininet.dl l" Alias "InternetOp enA" _ (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.dl l" Alias "InternetConnec tA" _ (ByVal hInternetSessio n 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.dl l" Alias "FtpGetFile A" _ (ByVal hFtpSession As Integer, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttri butes As Integer, _ ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean Private Declare Function FtpPutFile _
Lib "wininet.dl l" Alias "FtpPutFile A" _ (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.dl l" Alias "FtpDeleteFileA " _ (ByVal hFtpSession As Integer, _
ByVal lpszFileName As String) As Integer
Private Declare Function FtpSetCurrentDi rectory _
Lib "wininet.dl l" Alias "FtpSetCurrentD irectoryA" _ (ByVal hFtpSession As Integer, _
ByVal lpszDirectory As String) As Boolean
Private Declare Auto Function FtpFindFirstFil e _
Lib "wininet.dl l" Alias "FtpFindFirstFi leA" _ (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 InternetFindNex tFile _
Lib "wininet.dl l" Alias "InternetFindNe xtFileA" _ (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 dwFileAttribute s As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTim e As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer

<System.Runtim e.InteropServic es.MarshalAs (System.Runtime .InteropService s.UnmanagedType .ByValTStr, SizeConst:=260) > Public cFileName As String

<System.Runtim e.InteropServic es.MarshalAs (System.Runtime .InteropService s.UnmanagedType .ByValTStr, SizeConst:=14)> Public cAlternate As String
End Structure

HTH,

Jim Edgar
.

Nov 21 '05 #6

"Ron" <an*******@disc ussions.microso ft.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_P ASSIVE = &H8000000
Public Const INTERNET_FLAG_R ELOAD = &H80000000
Public Const INTERNET_OPTION _CONNECT_TIMEOU T = 2
Public Const INTERNET_OPTION _SEND_TIMEOUT = 5
Public Const INTERNET_OPTION _RECEIVE_TIMEOU T = 6
Public Const INTERNET_OPEN_T YPE_PRECONFIG = 0
Public Const INTERNET_INVALI D_PORT_NUMBER = 0
Public Const INTERNET_SERVIC E_FTP = 1
Public Const INTERNET_SERVIC E_GOPHER = &O2
Public Const INTERNET_SERVIC E_HTTP = 3
Public Const INTERNET_OPEN_T YPE_DIRECT = 1
Public Const INTERNET_OPEN_T YPE_PROXY = 3
Public Const INTERNET_DEFAUL T_FTP_PORT = 21
Public Const INTERNET_DEFAUL T_GOPHER_PORT = 70
Public Const INTERNET_DEFAUL T_HTTP_PORT = 80
Public Const INTERNET_DEFAUL T_HTTPS_PORT = 443
Public Const INTERNET_DEFAUL T_SOCKS_PORT = 1080

Public Const FTP_TRANSFER_TY PE_BINARY = &H2
Public Const FTP_TRANSFER_TY PE_ASCII = &H1

Public Const ERROR_NO_MORE_F ILES = 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*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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
16709
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 WriteFile I have written C code which works fine, just the VB translation/port
0
4269
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 as much as possible, so I'd like to call Xerces under the JAXP API. I'd like to validate the XML against a DTD, so that errors are flagged up to the user, and I can transcribe
11
6597
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 where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
9
7086
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 "no no" 3) are VB.Net windows, underneath the covers, Win32 windows? and can be treated as such?
6
1562
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 several more that have come up over the last few months, and it has raised a couple of questions the answers to which could plug a few holes in my knowledge. First, I'm uncomfortable using API calls purely because I don't fully understand the...
4
1557
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 the same logic to handle the calls. Calls in the VB.net code does not call the DLLs directly, but rather a custom dll wrapper class, so that the logic can be made for the VB code in the abstraction class. Initially, my idea was to create a...
3
2484
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 possible to create with only C++ then plz describe how!
12
3366
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 before. Thanks, MJK
11
4776
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; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3259
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 we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.