VB.Net and API

  • Thread starter Thread starter klabranche
  • Start date Start date
K

klabranche

Guest
I am trying to convert my VB6 class to a VB.Net Class. I have several APIs that the class calls. I am running into a problem with VB.Net using the API calls. How should the Below API look in VB.Net

VB6 Declaration

Private Declare Function NetServerEnum Lib "netapi32.dll" (btComputerName As Byte, _
ByVal lgLevel As Long, anBuffer As Any, lgPreferedMaxLen As Long, _
lgEntriesRead As Long, lgTotalEntries As Long, anServerType As Any, _
btDomain As Byte, lgResumeHandle As Long) As Long

So far I have done....
Private Declare Function NetServerEnum Lib "netapi32.dll" (ByRef btComputerName As Byte, ByVal lgLevel As Integer, ByRef anBuffer As Integer, ByRef lgPreferedMaxLen As Integer, ByRef lgEntriesRead As Integer, ByRef lgTotalEntries As Integer, ByRef anServerType As Integer, ByRef btDomain As Byte, ByRef lgResumeHandle As Integer) As Integer

The compiler doesnt like the "As Any" so I changed the declares to integers and now I get an INVALID_PARAMETER (error code 87) from the result of calling the API.

I also tried using the below but this to failed with another error....

Private Declare Function NetServerEnum Lib "netapi32.dll" (ByRef btComputerName As Byte, ByVal lgLevel As Integer, <MarshalAsAttribute(UnmanagedType.AsAny)> ByRef anBuffer As Object, ByRef lgPreferedMaxLen As Integer, ByRef lgEntriesRead As Integer, ByRef lgTotalEntries As Integer, <MarshalAsAttribute(UnmanagedType.AsAny)> ByRef anServerType As Object, ByRef btDomain As Byte, ByRef lgResumeHandle As Integer) As Integer


Any help would be appreciated...
 
Using NetServerEnum with VB.NET

Microsoft Knowledge Base Article - 198896 gives information on using NetServerEnum with 32 bit Visual Basic. Their syntax for the NetsServerEnum declaration is:

Private Declare Function NetServerEnum Lib "netapi32.dll" ( _
ByVal servername As String, _
ByVal level As Long, _
ByVal buffer As Long, _
ByVal prefmaxlen As Long, _
ByVal entriesread As Long, _
ByVal totalentries As Long, _
ByVal servertype As Long, _
ByVal domain As String, _
ByVal resumehandle As Long) As Long

However Ive had difficulties calling the function. I get a
System.NullReferenceException evidently because Im not initializing one of the parameters properly. I will post with more details. Meanwhile, check out the Knowledge Base article. If you get it to work, then please let me know.
 
Back
Top