Click here to Skip to main content
14,868,639 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Code convertor tool in Vb .net Pin
Blumen7-May-07 5:48
MemberBlumen7-May-07 5:48 
AnswerRe: Code convertor tool in Vb .net Pin
Dave Kreskowiak4-May-07 2:33
mveDave Kreskowiak4-May-07 2:33 
GeneralRe: Code convertor tool in Vb .net Pin
Blumen8-May-07 2:14
MemberBlumen8-May-07 2:14 
GeneralRe: Code convertor tool in Vb .net Pin
Dave Kreskowiak8-May-07 3:46
mveDave Kreskowiak8-May-07 3:46 
AnswerRe: Code convertor tool in Vb .net Pin
Paul Conrad4-May-07 14:00
professionalPaul Conrad4-May-07 14:00 
GeneralRe: Code convertor tool in Vb .net Pin
irrdev6-May-07 22:33
Memberirrdev6-May-07 22:33 
QuestionRASEnumEntries for VB.NET Pin
hellotkb3-May-07 17:45
Memberhellotkb3-May-07 17:45 
AnswerRe: RASEnumEntries for VB.NET Pin
Dave Kreskowiak4-May-07 6:26
mveDave Kreskowiak4-May-07 6:26 
It's a pain converting from VB6 to VB.NET, especially when you start calling into the Win32 API. VB6 and VB.NET differ in the way functon parameters are mashaled back and forth. This call in particular, is a b**** to get running.

First, you need to clean up the RAS_ENTRIES structure a bit. You need to tell the .NET CLR how to pack structure members together and how to pass the strings so it matches what the API expects. You also have to tell the CLR what the maximum size the strings are going to be when they are marshaled back to managed code.
<StructLayout(LayoutKind.Sequential,CharSet:=CharSet.Unicode)> _
Public Structure RASENTRYNAME
    Public dwSize As Integer
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public szEntryName As String
    Public dwFlags As Integer
    <MarshalAs(UnmanagedType.ByValTStr,SizeConst=261)> Public szPhonebook As String
End Structure

You didn't post what you put for the Declare, but it should look something like this:
Private Declare Auto Function RasEnumEntries Lin "rasapi32" ( _
        ByVal reserved As String, _
        ByVal phonebook As String, _
        <[In](), Out()> ByVal RasEntries() AS RASENTRYNAME, _
        ByRef BufferSize As Integer, _
        ByRef EntryCount As Integer) _
            As Integer

To call it, you have to be a little careful. You have to create an empty dummy entry and set the entries internal structure size before you call this function:
Dim bufferSize As Integer = Marshal.SizeOf(GetType(RASENTRYNAME))
Dim entryCount As Integer = 1
Dim entryNames(0) As RASENTRYNAME
Dim returnCode As Integer

entryNames(0).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
If rc = 0 Then
    ' Return, there was only one entry and it's been filled into the "dummy"
    ' entry that we made before calling RasEnumEntries.
End If

If rc <> 603 Then
    ' So if we get here, the call bombed.  It would be a good idea to find out why here!
    Return
End If

' 603 means that there are more entries than we have allocated space for.
' So, expand the entryNames array and make sure we fill in the structure size
' for every entry in the array!  This is important!!  Without it, you'll get 632 errors!
ReDim entryNames(numEntries - 1)
For i As Integer = 0 to numEntries - 1
    entryNames(i).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
Next
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
'
'  Now we should have all the Ras entries.  Do with as you will...




Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
2006, 2007


GeneralRe: RASEnumEntries for VB.NET Pin
hellotkb4-May-07 20:12
Memberhellotkb4-May-07 20:12 
GeneralRe: RASEnumEntries for VB.NET Pin
Claudio Nicora29-Nov-09 22:15
MemberClaudio Nicora29-Nov-09 22:15 
AnswerRe: RASEnumEntries for VB.NET Pin
JfCode10-Jan-12 4:44
MemberJfCode10-Jan-12 4:44 
Questionremoting problem Pin
neodeaths3-May-07 16:50
Memberneodeaths3-May-07 16:50 
AnswerRe: remoting problem Pin
Paul Conrad14-Jul-07 6:50
professionalPaul Conrad14-Jul-07 6:50 
GeneralRe: remoting problem Pin
neodeaths15-Jul-07 16:46
Memberneodeaths15-Jul-07 16:46 
GeneralRe: remoting problem Pin
Paul Conrad15-Jul-07 17:08
professionalPaul Conrad15-Jul-07 17:08 
Questionhow can i send infomation from 1 pc to another>? Pin
neodeaths3-May-07 16:12
Memberneodeaths3-May-07 16:12 
AnswerRe: how can i send infomation from 1 pc to another>? Pin
Blumen3-May-07 23:07
MemberBlumen3-May-07 23:07 
Question.NET Framework Content Training Pin
JatinerS3-May-07 13:43
MemberJatinerS3-May-07 13:43 
QuestionProof of the .NET 3.0 Installation Pin
Brendan Vogt3-May-07 7:21
MemberBrendan Vogt3-May-07 7:21 
AnswerRe: Proof of the .NET 3.0 Installation Pin
Dave Kreskowiak3-May-07 7:49
mveDave Kreskowiak3-May-07 7:49 
GeneralRe: Proof of the .NET 3.0 Installation Pin
Brendan Vogt3-May-07 19:54
MemberBrendan Vogt3-May-07 19:54 
GeneralRe: Proof of the .NET 3.0 Installation Pin
Dave Kreskowiak4-May-07 2:28
mveDave Kreskowiak4-May-07 2:28 
QuestionRe: Proof of the .NET 3.0 Installation Pin
Brendan Vogt4-May-07 2:35
MemberBrendan Vogt4-May-07 2:35 
AnswerRe: Proof of the .NET 3.0 Installation Pin
Scott Dorman4-May-07 4:08
professionalScott Dorman4-May-07 4:08 
AnswerRe: Proof of the .NET 3.0 Installation Pin
kubben3-May-07 14:04
Memberkubben3-May-07 14:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.