NetShareEnum Error 87 in Win98

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Marc St-Hilaire

    #1

    NetShareEnum Error 87 in Win98

    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(L ayoutKind.Seque ntial)> _
    Private Structure SHARE_INFO_50
    <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    Dim netname As String
    Dim type As Integer
    Dim flags As Int32
    <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    Dim remark As String
    <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    Dim path As String
    <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    Dim rw_password As String
    <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    Dim ro_password As String
    End Structure

    Private Declare Ansi Function NetShareEnum98 Lib "svrapi.dll " Alias
    "NetShareEn um" ( _
    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.AllocHG lobal(buffer)
    level = 50
    structSize = Marshal.SizeOf( GetType(SHARE_I NFO_50))
    buffer = structSize * 20
    bServer = ""

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


  • Mattias Sjögren

    #2
    Re: NetShareEnum Error 87 in Win98

    Jean-Marc,
    [color=blue]
    ><StructLayout( LayoutKind.Sequ ential)> _
    >Private Structure SHARE_INFO_50
    > <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    > Dim netname As String
    > Dim type As Integer
    > Dim flags As Int32
    > <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    > Dim remark As String
    > <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    > Dim path As String
    > <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    > Dim rw_password As String
    > <MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.LPWS tr)> _
    > Dim ro_password As String
    >End Structure[/color]

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

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

    type should be a Byte and flags a Short.

    [color=blue]
    >Private Declare Ansi Function NetShareEnum98 Lib "svrapi.dll " Alias
    >"NetShareEnu m" ( _
    > 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[/color]

    ServerName, cBuffer and BufPtr should be passed ByVal.

    All Integers except the return type should be Short.

    [color=blue]
    >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.AllocHG lobal(buffer)[/color]

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


    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...