Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. help Converting the below project in vb.net

help Converting the below project in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpcomhelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vbinfo
    wrote on last edited by
    #1

    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

    M 2 Replies Last reply
    0
    • V vbinfo

      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

      M Offline
      M Offline
      mikasa
      wrote on last edited by
      #2

      What are you trying to do? The whole control or just the Server enumeration?

      V 1 Reply Last reply
      0
      • M mikasa

        What are you trying to do? The whole control or just the Server enumeration?

        V Offline
        V Offline
        vbinfo
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • V vbinfo

          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

          M Offline
          M Offline
          mikasa
          wrote on last edited by
          #4

          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.

          V 1 Reply Last reply
          0
          • M mikasa

            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.

            V Offline
            V Offline
            vbinfo
            wrote on last edited by
            #5

            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

            T 2 Replies Last reply
            0
            • V vbinfo

              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

              T Offline
              T Offline
              Tim McCurdy
              wrote on last edited by
              #6

              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 default

               CurrentItem += 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 Boolean

               CurrentItem += 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.

              1 Reply Last reply
              0
              • V vbinfo

                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

                T Offline
                T Offline
                Tim McCurdy
                wrote on last edited by
                #7

                ...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 / Byref

                 If (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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups