|
There are some RASEnumEntries projects written in VB6. However there isn't any project written in vb.net in the Internet. I have tried converting a VB6 project into VB.Net but i hit the 632 - Invalid size error. Can someone enlighted me? Here are part of my source code:
'Structure for RASENTRYNAME (Did i get the structure rite?)
'==============================================
Private Structure RAS_ENTRIES
Dim dwFlags As Integer
Dim dwSize As Integer
<vbfixedarray(256)> Dim szEntryname() As Byte
Public Sub Initialize()
ReDim szEntryname(256)
End Sub
End Structure
'==============================================
Function RasEnumEntriesA (Am i assigning the correct structure size?)
'==============================================
Dim lngSize As Integer
Dim lngEntries As Integer
Dim lngIndex As Integer
Dim result As Long
Dim RAS(255) As RAS_ENTRIES
Erase sDunList
RAS(0).dwSize = Marshal.SizeOf(RAS(0))
lngSize = 256 * RAS(0).dwSize
result = RasEnumEntriesA(vbNullString, vbNullString, RAS(0), lngSize, lngEntries)
'================================================
Any help is appreciated. Thanks alot!
Regards,
Max
|
|
|
|
|
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
|
|
|
|
|
Hi Dave,
I got your advise. Finally the codes are running fine with the result i want.
Many thanks to u!!
Best Rdgs,
Max
|
|
|
|
|
@Dave: your code works perfectly, but on my side some cleanup was required.
So I decided to post a complete and clean version...
Private Const MAX_PATH As Integer = 260 + 1
Private Const MAX_RAS_ENTRY_NAMES As Integer = 256 + 1
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure RASENTRYNAME
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_RAS_ENTRY_NAMES)> _
Public szEntryName As String
Public dwFlags As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
Public szPhonebook As String
End Structure
Private Declare Auto Function RasEnumEntries Lib "rasapi32.dll" ( _
ByVal reserved As String, _
ByVal phonebook As String, _
<[In](), Out()> ByVal RasEntries() As RASENTRYNAME, _
ByRef BufferSize As Integer, _
ByRef EntryCount As Integer _
) As Integer
''' <summary>
''' Returns an array with available RAS connection names
''' </summary>
Public Shared Function GetConnectionsNames() As String()
Dim res As New List(Of String)
Try
Dim bufferSize As Integer = Marshal.SizeOf(GetType(RASENTRYNAME))
Dim entryCount As Integer = 1
Dim entryNames(0) As RASENTRYNAME
Dim rc As Integer
entryNames(0).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
If rc = 0 Then
' There was only one entry and it's been filled into the "dummy"
' entry that we made before calling RasEnumEntries.
res.Add(entryNames(0).szEntryName.Trim)
ElseIf rc = 603 Then
' 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(entryCount - 1)
For i As Integer = 0 To entryCount - 1
entryNames(i).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
Next
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
For i As Integer = 0 To entryCount - 1
res.Add(entryNames(i).szEntryName.Trim)
Next
Else
' So if we get here, the call bombed. It would be a good idea to find out why here!
MsgBox("Error reading RAS connections names, error code:" & rc.ToString(), MsgBoxStyle.SystemModal)
End If
Catch ex As Exception
MsgBox("Error reading RAS connection names: " & ex.Message.ToString(), MsgBoxStyle.SystemModal)
End Try
Return res.ToArray
End Function
Thanks again.
Caudio
|
|
|
|
|
works good Seven64
merci beaucoup
quoi de 9 docteur
|
|
|
|
|
|
Have you resolved this?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
yep needed to twink it a little. but it works fine now ended up using an dll file i got online thouh to do the remoting that is
|
|
|
|
|
Glad you got it to work
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
hi i am trying to send a int data from1 pc running an window applcation to another pc running another window application.
i tried remoting but it seems too hard is there an easier way to do this please help
|
|
|
|
|
Hi,
I believe Socket programming would be suitable here, and its not that complicated.Try this:
http://www.codeproject.com/cs/internet/socketsincsharp.asp
blumen
|
|
|
|
|
My name is Jatiner and I work for Microsoft on the TechEd event. I generally read IT blogs to keep up with what is going on in the industry and decided to jump on in with a little plug for TechEd 2007 (June 4 – 8). This year we’ve dedicated 50% of the event content to developer specific tools with deep technical training that covers Visual Studio® 2005, Windows Vista™ development and the .NET Framework. You can also get in-depth information on building software using Visual C++®, Visual Basic® and Visual C#®. The incredible amount of information you can learn at TechEd is awesome but it is also an incredible place to network and let loose a little. The event is in Orlando, FL this year so the attendee party is at Universal Studios Islands of Adventure and the place is reserved for TechEd attendees only! Trust me, these parties are a blast. If you decide to go you should register now before it sells out like it did last year…we are also offering a bit of an incentive, all registrations before May 11th are entered to win either 1 of 5 Xbox 360 Elites (killer graphics) or 1 of 5 Amex gift cards (Disney ain’t cheap!) www.microsoft.com/teched
Jatinder Singh
|
|
|
|
|
Hi,
I installed .NET 3.0 and I want to know how do I see that it was installed? I installed Enterprise Library April 2007 and it went through fine, but it would've gone through even if I had only 2.0 installed.
Please can someone advise??
Regards
ma se
|
|
|
|
|
Add/Remove Programs control panel is an easy way.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
Thanks for the feedback, I don't know why I didn't check this in the first place. I probably did but overlooked it somewhere.
Just a quick question on Enterprise Library April 2007. If 3.0 is installed, it will install all the necessary projects for 3.0? Is there a way that I can check it?
Have you started working on .NET 3.5?? Is there anything available for download. Do you know if it is going to be like 3.0 where it won't be necessarily required to use it if you have 2.0?? 3.0 is basically for workflows, right?
Thanks
ma se
|
|
|
|
|
ma se wrote: Just a quick question on Enterprise Library April 2007. If 3.0 is installed, it will install all the necessary projects for 3.0? Is there a way that I can check it?
No idea. I don't use the Enterprise Library.
ma se wrote: Have you started working on .NET 3.5??
No, I haven't had any time to play around with it.
ma se wrote: Is there anything available for download.
If you want to play around with the next release of Visual Studio and .NET 3.5, go here[^]. Warning - the downloads are massive.
ma se wrote: 3.0 is basically for workflows, right?
Wrong. .NET 3.0 is actually .NET 2.0 with some extensions added to it. As far as the Base Class Library, there's no difference between the two. .NET just adds Windows Presentation Foundation, Windows Communication Foundation, Windows Workflow Foundation, and CardSpace support.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Dave Kreskowiak wrote: .NET 3.0 is actually .NET 2.0 with some extensions added to it. As far as the Base Class Library, there's no difference between the two.
Will this still be the case with .NET 3.5? Where can I found out what new features they are planning to add with .NET 3.5?
|
|
|
|
|
ma se wrote: Will this still be the case with .NET 3.5? Where can I found out what new features they are planning to add with .NET 3.5?
Yes, the .NET 3.5 release contains the following:
|
|
|
|
|
You can always check your c:\windows\microsoft.net\framework directory to see if you have a 3.** directory. That is where the framework files are stored.
Ben
|
|
|
|
|
Hi Ben,
Just a quick question on Enterprise Library April 2007. If 3.0 is installed, it will install all the necessary projects for 3.0? Is there a way that I can check it?
Have you started working on .NET 3.5?? Is there anything available for download. Do you know if it is going to be like 3.0 where it won't be necessarily required to use it if you have 2.0?? 3.0 is basically for workflows, right?
Thanks
ma se
|
|
|
|
|
|
Actually, you don't need to download orcas for this. You can download the different packs that you need from http://www.netfx3.com/[^]. Take a look at the areas on the right, e.g. Windows Presentation Foundation.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
problem while deserialing image
how can i send image through msmq and retrive it
|
|
|
|
|
What kind of image? How is it represented in your code?
|
|
|
|
|
how does one change the properties of an attribute at run time. The quasi-code at the end hereof is an attempt to show what I want to do.
It seems that even tho member's can change the value of their own and other members attributes (via the attributes property set accessors), when another member gets that attribute the attribute's state variables revert to their compile (load) time value. If you can follow my code, the interrogation of StringProperty's myStateAttribute in the SomeMethod code always yields a value of myStates.InitialValue in the State property of the myStateAttribute attached to the StringProperty, even tho it gets changed to InError or CurrentValue in the StringProperty set accessor.
In this code the attributes content is pertinent to the runtime state of the member instance to which it's applied, i.e. it is <u>dynamic</u> metadata rather than static metadata such as DisplayName etc.
<code>
enum myStates{InitialValue, InError, HasChanged, CurrentValue,}
class myStateAttribute : Attribute {
public myStates State {get this.theState;}set{this.theState=value;}
public myStateAttribute() {
this.State = myStates.InitialValue;
}
private myStates theState;
}
...
[myState()]
string StringProperty {
get {return this.theStringProperty)
set (
{
PropertyInfo _p = this.GetType().GetProperty(_n, BindingFlags....
object[] _o = _p.GetProperty(typeof(myStateAttribute);
myStateAttribute _a;
if (_o.Length == 1 && _o is myStateAttribute){
_a = (myStateAttribute) _o;
else
throw new ApplicationException("whoops, forgot the myState attribute");
if (value!=null &&
value.Length < Properties.Settings.MinStringSize ||
value.Length > Properties.Settings.maxStringSize) {
string _n = new StackTrace().GetFrame(0).GetMethod().Name.SubString(4);
_a.State = myStates.InError;
}
else
a.State = myStates.CurrentValue;
}
}
}
.......
private whatever SomeMethod()
{
...
data.PropertyString = someOtherString;
interrogate PropertyString's myStateAttribute and act accordingly
}
</code>
|
|
|
|
|