which API can list out all my dialup connection
hi all,
i looking for many days on this topic already. as i know maybe is using RASAPI32 to do this. but i have vb6 code only. when i convert to vb.net. there have problem like "As Any" not supported by .net, declaration "TYPE" also not supported and etc. who can teach me how to modified?
code:
Private Type RAS_ENTRIES
dwSize As Long
szEntryname(256) As Byte
End Type
Private Declare Function RasEnumEntriesA Lib "rasapi32.dll" (ByVal reserved As String, ByVal lpszPhonebook As String, lprasentryname As Any, lpcb As Long, lpcEntries As Long) As Long
sub
Dim plSize As Long
Dim plEntries As Long
Dim psConName As String
Dim plIndex As Long
Dim RAS(255) As RAS_ENTRIES
Erase sDunList()
RAS(0).dwSize = 264
plSize = 256 * RAS(0).dwSize
Call RasEnumEntriesA(vbNullString, vbNullString, RAS(0), plSize, plEntries)
plEntries = plEntries - 1
If plEntries >= 0 Then
ReDim sDunList(plEntries)
For plIndex = 0 To plEntries
psConName = StrConv(RAS(plIndex).szEntryname(), vbUnicode)
sDunList(plIndex) = Left$(psConName, InStr(psConName, vbNullChar) - 1)
Next plIndex
End If
end sub
thanks~
Re: which API can list out all my dialup connection
"As Any" can be specified as which ever type you are dealing with but generically you can use Object but you wil need to create an instance of it first.
Code:
Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
<StructLayout(LayoutKind.Sequential)> _
Private Structure RAS_ENTRIES
Private dwSize As Integer
Private szEntryname() As Byte
End Structure
<DllImport("rasapi32.dll", CharSet:=CharSet.Auto, EntryPoint:="rasapi32.dll")> _
Private Shared Function RasEnumEntries( _
ByVal reserved As String, _
ByVal lpszPhonebook As String, _
ByRef lprasEntryName As RAS_ENTRIES, _
ByRef lpcb As Integer, _
ByRef lpcEntries As Integer) As Integer
End Function
End Class
Re: which API can list out all my dialup connection
thanks, after i try ur method, it shown error at below part
sub ListDun(ByRef sDunList() As String)
Dim plSize As Long
Dim plEntries As Long
Dim psConName As String
Dim plIndex As Long
Dim RAS(255) As RAS_ENTRIES
Erase sDunList() 'error : number of indices is less than the number of dimension of the indexed arrayRAS(0).dwSize = 264
plSize = 256 * RAS(0).dwSize
Call RasEnumEntriesA(vbNullString, vbNullString, RAS(0), plSize, plEntries)
plEntries = plEntries - 1
If plEntries >= 0 Then
ReDim sDunList(plEntries)
For plIndex = 0 To plEntries
psConName = StrConv(RAS(plIndex).szEntryname(), vbUnicode) ' error: Convert method not support
sDunList(plIndex) = Left$(psConName, InStr(psConName, vbNullChar) - 1)
Next plIndex
End If
end sub
beside that, other no blue underline shown, how to modified it?? thanks
Re: which API can list out all my dialup connection
Please use [code] tags next time so its easier to read.
RAS(0).dwSize = 264 'Exceeds the 255 dimensioned.
Re: which API can list out all my dialup connection
ok, i will next time.
but the error is at " Erase sDUNList() " and " ConvStr ", bold text.
how do i solve that?