G
Guest
Hi
I'm trying to enum all the RAS entries but continually get error 632 (invalid structure size). I know there are different sizes of the structure depending on version and I've tried with and without the Win2000 additional struct members...
The sizes should be either 264 or 532 depending on version - In VB6 it works fine with 264 - but not VB.Ne
I think it may be something to do with the way I'm writing the value into the dwSize member of the first structure (i.e. Marshal.WriteInt32(bufptr, structsize)
Anyone provide any hints ??? - Thanks .. Ke
I'm using the foloowing declaration
<StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Ansi)>
Public Structure RASENTRYNAM
Public dwSize As Intege
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=257)> Public szEntryname As Strin
'Public dwFlags As Intege
'<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=261)> Public szPhonebook As Strin
End Structur
Public Declare Auto Function RasEnumEntries Lib "rasapi32.dll" (
ByVal lpcsReserved As String,
ByRef lpcsPhoneBook As String,
ByRef lpRASentries As IntPtr,
ByRef lpSize As Integer,
ByRef lpCount As Integer) As Intege
and the following in my code..
Private Function Connect() As Boolea
Dim structtype As Type = GetType(RASENTRYNAME
Dim structsize As Integer = Marshal.SizeOf(structtype
Dim maxcount As Integer = 25
Dim bufsize As Integer = maxcount * structsiz
Dim bufptr As IntPt
Dim realcount As Integer =
Dim retcode As Intege
Dim TRasCon As RASENTRYNAME(
Dim bResult As Boolean = Fals
bufptr = Marshal.AllocHGlobal(bufsize
Marshal.WriteInt32(bufptr, structsize
retcode = RasEnumEntries(vbNullString, vbNullString, bufptr, bufsize, realcount
If (retcode = 0) And (realcount > 0) The
ReDim TRasCon(realcount - 1
Dim i As Intege
Dim runptr As IntPtr = bufpt
For i = 0 To (realcount - 1
TRasCon(i) = CType(Marshal.PtrToStructure(runptr, structtype), RASENTRYNAME
If (TRasCon(i).szEntryname = sEntryName) The
MsgBox(TRasCon(i).szEntryname
End I
runptr = New IntPtr(runptr.ToInt32 + structsize
Nex
End I
Marshal.FreeHGlobal(bufptr
End Function
I'm trying to enum all the RAS entries but continually get error 632 (invalid structure size). I know there are different sizes of the structure depending on version and I've tried with and without the Win2000 additional struct members...
The sizes should be either 264 or 532 depending on version - In VB6 it works fine with 264 - but not VB.Ne
I think it may be something to do with the way I'm writing the value into the dwSize member of the first structure (i.e. Marshal.WriteInt32(bufptr, structsize)
Anyone provide any hints ??? - Thanks .. Ke
I'm using the foloowing declaration
<StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Ansi)>
Public Structure RASENTRYNAM
Public dwSize As Intege
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=257)> Public szEntryname As Strin
'Public dwFlags As Intege
'<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=261)> Public szPhonebook As Strin
End Structur
Public Declare Auto Function RasEnumEntries Lib "rasapi32.dll" (
ByVal lpcsReserved As String,
ByRef lpcsPhoneBook As String,
ByRef lpRASentries As IntPtr,
ByRef lpSize As Integer,
ByRef lpCount As Integer) As Intege
and the following in my code..
Private Function Connect() As Boolea
Dim structtype As Type = GetType(RASENTRYNAME
Dim structsize As Integer = Marshal.SizeOf(structtype
Dim maxcount As Integer = 25
Dim bufsize As Integer = maxcount * structsiz
Dim bufptr As IntPt
Dim realcount As Integer =
Dim retcode As Intege
Dim TRasCon As RASENTRYNAME(
Dim bResult As Boolean = Fals
bufptr = Marshal.AllocHGlobal(bufsize
Marshal.WriteInt32(bufptr, structsize
retcode = RasEnumEntries(vbNullString, vbNullString, bufptr, bufsize, realcount
If (retcode = 0) And (realcount > 0) The
ReDim TRasCon(realcount - 1
Dim i As Intege
Dim runptr As IntPtr = bufpt
For i = 0 To (realcount - 1
TRasCon(i) = CType(Marshal.PtrToStructure(runptr, structtype), RASENTRYNAME
If (TRasCon(i).szEntryname = sEntryName) The
MsgBox(TRasCon(i).szEntryname
End I
runptr = New IntPtr(runptr.ToInt32 + structsize
Nex
End I
Marshal.FreeHGlobal(bufptr
End Function