help Converting the below project in vb.net
-
Hi, I am trying to convert the below code to a vb.net project. I have tried all sorts but didnt manage to do it. can anybody help? :confused: http://www.codeproject.com/csharp/servercombobox.asp?target=servercombobox Thanks A lot Gabriel vbnetuk@yahoo.co.uk
-
Hi, I am trying to convert the below code to a vb.net project. I have tried all sorts but didnt manage to do it. can anybody help? :confused: http://www.codeproject.com/csharp/servercombobox.asp?target=servercombobox Thanks A lot Gabriel vbnetuk@yahoo.co.uk
-
I managed to convert the server enumeration no problem it's driving me mad and would seriously appreaciate somebody's help. There is only one class "Network Management" and it's not that big but non knowing c# that well it's proving a nightmare. I only need to convert that class. Thanks A lot Gabriel vbnetuk@yahoo.co.uk
-
Hi, I am trying to convert the below code to a vb.net project. I have tried all sorts but didnt manage to do it. can anybody help? :confused: http://www.codeproject.com/csharp/servercombobox.asp?target=servercombobox Thanks A lot Gabriel vbnetuk@yahoo.co.uk
-
Well, I am not going to go in depth, converting this stuff takes a lot of time and patience. However, if you want help on a specific piece, post it here.
I totally understand that .Thanks There are 2 piecies of code that creates problem for me 1) public bool MoveNext() { bool result = false; if ( ++currentItem < itemCount ) { int newOffset = serverInfoPtr.ToInt32() + SERVER_INFO_101_SIZE * currentItem; Win32API.SERVER_INFO_101 si = (Win32API.SERVER_INFO_101) Marshal.PtrToStructure(new IntPtr(newOffset), typeof(Win32API.SERVER_INFO_101)); currentServerName = Marshal.PtrToStringAuto(si.lpszServerName); result = true; } return result; } ===================== 2)public static ServerType GetServerType(string serverName) { ServerType result = ServerType.None; IntPtr serverInfoPtr = IntPtr.Zero; uint rc = Win32API.NetServerGetInfo( serverName, 101, ref serverInfoPtr ); if ( rc != 0 ) { Win32API.SERVER_INFO_101 si = (Win32API.SERVER_INFO_101) Marshal.PtrToStructure(serverInfoPtr, typeof(Win32API.SERVER_INFO_101)); result = (ServerType) si.dwType; Win32API.NetApiBufferFree(serverInfoPtr); serverInfoPtr = IntPtr.Zero; } return result; } Thanks A lot Gabriel vbnetuk@yahoo.co.uk
-
I totally understand that .Thanks There are 2 piecies of code that creates problem for me 1) public bool MoveNext() { bool result = false; if ( ++currentItem < itemCount ) { int newOffset = serverInfoPtr.ToInt32() + SERVER_INFO_101_SIZE * currentItem; Win32API.SERVER_INFO_101 si = (Win32API.SERVER_INFO_101) Marshal.PtrToStructure(new IntPtr(newOffset), typeof(Win32API.SERVER_INFO_101)); currentServerName = Marshal.PtrToStringAuto(si.lpszServerName); result = true; } return result; } ===================== 2)public static ServerType GetServerType(string serverName) { ServerType result = ServerType.None; IntPtr serverInfoPtr = IntPtr.Zero; uint rc = Win32API.NetServerGetInfo( serverName, 101, ref serverInfoPtr ); if ( rc != 0 ) { Win32API.SERVER_INFO_101 si = (Win32API.SERVER_INFO_101) Marshal.PtrToStructure(serverInfoPtr, typeof(Win32API.SERVER_INFO_101)); result = (ServerType) si.dwType; Win32API.NetApiBufferFree(serverInfoPtr); serverInfoPtr = IntPtr.Zero; } return result; } Thanks A lot Gabriel vbnetuk@yahoo.co.uk
Ok, let me attempt this blindly since I do not have all the code LOL! Lets start with the First one. I may rename variables but you'll get the idea. ;) The number one thing in dealing with API Calls is this: Imports System.Runtime.InteropServices 'Put in Header
'=====================
'1.)
Public Function MoveNext() As Boolean
Dim svrInfo As Win32API.SERVER_INFO_101
Dim bResult as Boolean = False 'Unnecessary because Boolean = False by defaultCurrentItem += 1 'Increment the CurrentItem Counter If (CurrentItem < ItemCount) Then Dim iOffset As Integer = (svrInfoPtr.ToInt32 + SERVER\_INFO\_101\_SIZE \* CurrentItem) Marshal.PtrToStructure(New IntPtr(iOffset), GetType(svrInfo)) CurrentServerName = Marshal.PtrToStringAuto(svrInfo.lpszServerName) bResult = True End If Return bResult
End Function
'=====================Lets make it a little better by using some Error Trapping. Try this next example:
'=====================
'1.)
Public Function MoveNext() As Boolean
Dim svrInfo As Win32API.SERVER_INFO_101
Dim bSuccess As BooleanCurrentItem += 1 'Increment the CurrentItem Counter If (CurrentItem >= ItemCount) Then Return False 'Exit if the Item is outside the Memory Address Range Try Dim iOffset As Integer = (svrInfoPtr.ToInt32 + SERVER\_INFO\_101\_SIZE \* CurrentItem) Marshal.PtrToStructure(New IntPtr(iOffset), GetType(svrInfo)) CurrentServerName = Marshal.PtrToStringAuto(svrInfo.lpszServerName) bSuccess = True Catch 'Display Error Message if you want bSuccess = False End Try Return bSuccess
End Function
'=====================To be continued... Not all those who are lost are looking to be found. But of those who are lost and those who are found, all are looking for something higher than themselves.
-
I totally understand that .Thanks There are 2 piecies of code that creates problem for me 1) public bool MoveNext() { bool result = false; if ( ++currentItem < itemCount ) { int newOffset = serverInfoPtr.ToInt32() + SERVER_INFO_101_SIZE * currentItem; Win32API.SERVER_INFO_101 si = (Win32API.SERVER_INFO_101) Marshal.PtrToStructure(new IntPtr(newOffset), typeof(Win32API.SERVER_INFO_101)); currentServerName = Marshal.PtrToStringAuto(si.lpszServerName); result = true; } return result; } ===================== 2)public static ServerType GetServerType(string serverName) { ServerType result = ServerType.None; IntPtr serverInfoPtr = IntPtr.Zero; uint rc = Win32API.NetServerGetInfo( serverName, 101, ref serverInfoPtr ); if ( rc != 0 ) { Win32API.SERVER_INFO_101 si = (Win32API.SERVER_INFO_101) Marshal.PtrToStructure(serverInfoPtr, typeof(Win32API.SERVER_INFO_101)); result = (ServerType) si.dwType; Win32API.NetApiBufferFree(serverInfoPtr); serverInfoPtr = IntPtr.Zero; } return result; } Thanks A lot Gabriel vbnetuk@yahoo.co.uk
...Continuation:
'=====================
'2)
Public Function GetServerType(ByVal ServerName As String) As ServerTypes
Dim svrInfoPtr As IntPtr = IntPtr.Zero
Dim svrInfo As Win32.SERVER_INFO_101
Dim hResult As Integer = Win32API.NetServerGetInfo(ServerName, 101, svrInfoPtr) 'Make sure the API Declarations have the Appropriate Byval / ByrefIf (hResult <> 0) Then 'Marshal.PtrToStructure(svrInfoPtr, GetType(svrInfo)) Marshal.PtrToStructure(svrInfoPtr, svrInfo) Return Ctype(svrInfo.dwType, ServerTypes) Else Return ServerTypes.None End If
End Function
I am sorry if there is anything wrong with these Posts...again, I did this all by looking at it and I did not "Pre-Code" this to see if it works. Good luck! Not all those who are lost are looking to be found. But of those who are lost and those who are found, all are looking for something higher than themselves.