NetShareEnum Error 87 in Win98

  • Thread starter Jean-Marc St-Hilaire
  • Start date
J

Jean-Marc St-Hilaire

I need to access Windows API NetShareEnum. It is working fine in the post
Win98 version but the Win98 function is returning me error number 87
(Invalid parameters)

Whats I am doing wrong ?

Following is my code

Thanks

Jean-Marc St-Hilaire
-----------------------------------

<StructLayout(LayoutKind.Sequential)> _
Private Structure SHARE_INFO_50
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim netname As String
Dim type As Integer
Dim flags As Int32
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim remark As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim path As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim rw_password As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim ro_password As String
End Structure

Private Declare Ansi Function NetShareEnum98 Lib "svrapi.dll" Alias
"NetShareEnum" ( _
ByRef ServerName As String, _
ByVal level As Integer, _
ByRef BufPtr As IntPtr, _
ByRef cBuffer As Integer, _
ByRef entriesread As Integer, _
ByRef totalentries As Integer _
) As Integer

Dim bServer As String
Dim level As Integer
Dim bufptr As IntPtr
Dim buffer As Integer
Dim dwEntriesRead As Integer = 0
Dim dwTotalEntries As Integer = 0


bufptr = Marshal.AllocHGlobal(buffer)
level = 50
structSize = Marshal.SizeOf(GetType(SHARE_INFO_50))
buffer = structSize * 20
bServer = ""

erreurLvl = NetShareEnum98( _
bServer, _
level, _
bufptr, _
buffer, _
dwEntriesRead, _
dwTotalEntries)
 
M

Mattias Sjögren

Jean-Marc,
<StructLayout(LayoutKind.Sequential)> _
Private Structure SHARE_INFO_50
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim netname As String
Dim type As Integer
Dim flags As Int32
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim remark As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim path As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim rw_password As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Dim ro_password As String
End Structure

netname, rw_password and ro_password are fixed length strings with
sizes 13, 9 and 9 respectively, so you should use
UnmangedType.ByValTStr for them.

For the other string members, you can delete the MarshalAs attribute
(or change it to use UnmanagedType.LPStr).

type should be a Byte and flags a Short.

Private Declare Ansi Function NetShareEnum98 Lib "svrapi.dll" Alias
"NetShareEnum" ( _
ByRef ServerName As String, _
ByVal level As Integer, _
ByRef BufPtr As IntPtr, _
ByRef cBuffer As Integer, _
ByRef entriesread As Integer, _
ByRef totalentries As Integer _
) As Integer

ServerName, cBuffer and BufPtr should be passed ByVal.

All Integers except the return type should be Short.

Dim bServer As String
Dim level As Integer
Dim bufptr As IntPtr
Dim buffer As Integer
Dim dwEntriesRead As Integer = 0
Dim dwTotalEntries As Integer = 0


bufptr = Marshal.AllocHGlobal(buffer)

Since buffer is uninitialized at this point and has the default value
of 0, you're allocating a zero length buffer.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top