Click here to Skip to main content
16,010,268 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: New MSDN article (flaw?) Pin
Paul Riley1-Oct-02 14:06
Paul Riley1-Oct-02 14:06 
GeneralRe: New MSDN article (flaw?) Pin
Daniel Turini3-Oct-02 22:47
Daniel Turini3-Oct-02 22:47 
GeneralError BC30311. Can't convert Pin
sybux200030-Sep-02 10:49
sybux200030-Sep-02 10:49 
GeneralRe: Error BC30311. Can't convert Pin
Vipul Bhatt1-Oct-02 2:29
Vipul Bhatt1-Oct-02 2:29 
GeneralRe: Error BC30311. Can't convert Pin
sybux20001-Oct-02 12:39
sybux20001-Oct-02 12:39 
Generalstart page Pin
FreJa30-Sep-02 7:13
FreJa30-Sep-02 7:13 
GeneralNetServerEnum Pin
Vipul Bhatt29-Sep-02 20:08
Vipul Bhatt29-Sep-02 20:08 
GeneralRe: NetServerEnum Pin
Richard Deeming30-Sep-02 1:28
mveRichard Deeming30-Sep-02 1:28 
The error message usually means that the declaration is wrong, i.e. passing arguments ByVal instead of ByRef.

The C++ declaration is:
NET_API_STATUS NetServerEnum(
  LPCWSTR servername,        // [in] Reserved - must be 0
                             //
  DWORD level,               // [in] Level - 100 or 101
                             //
  LPBYTE* bufptr,            // [out] Pointer to the buffer that receives the data.
                             // This buffer is allocated by the system and must be 
                             // freed using the NetApiBufferFree function. Note 
                             // that you must free the buffer even if the function 
                             // fails with ERROR_MORE_DATA. 
                             //
  DWORD prefmaxlen,          // [in] Prefered max length of returned data (bytes)
                             //
  LPDWORD entriesread,       // [out] Pointer to a value that receives the 
                             // count of elements actually enumerated.
                             //
  LPDWORD totalentries,      // [out] Pointer to a value that receives the total 
                             // number of visible servers and workstations on 
                             // the network. 
                             //
  DWORD servertype,          // [in] Specifies a value that filters the server 
                             // entries to return from the enumeration. 
                             //
  LPCWSTR domain,            // [in] Pointer to a constant string that specifies 
                             // the name of the domain for which a list of 
                             // servers is to be returned.
                             //
  LPDWORD resume_handle      // [out] Reserved - must be 0
);

In VB.NET, this translates to:
Public Declare Function NetServerEnum Lib "netapi32" ( _
    ByVal ServerName As IntPtr, _
    ByVal Level As Integer, _
    ByRef Buffer As IntPtr, _
    ByVal PrefMaxLen As Integer, _
    ByRef EntriesRead As Integer, _
    ByRef TotalEntries As Integer, _
    ByVal ServerType As Integer, _
    <MarshalAs(UnmanagedType.LPWStr)> _
    ByVal Domain As String, _
    ByVal ResumeHandle As IntPtr _
) As Integer

You then call it as:
...
Dim EntriesRead As Integer = 0
Dim TotalEntries As Integer = 0
Dim Buffer As IntPtr = IntPtr.Zero

Dim nRes As Integer = NetServerEnum( _
    IntPtr.Zero, _
    Level, _
    Buffer, _
    -1, _
    EntriesRead, _
    TotalEntries, _
    ServerType, _
    DomainName, _
    IntPtr.Zero _
)

Try
    'Do some stuff here
    ...
Finally
    'Clean up buffer
    If Not(Buffer.Equals(IntPtr.Zero)) Then
        NetApiBufferFree(Buffer)
    End If
End Try

GeneralRe: NetServerEnum Pin
Vipul Bhatt27-Oct-02 22:50
Vipul Bhatt27-Oct-02 22:50 
GeneralRe: NetServerEnum Pin
Richard Deeming30-Sep-02 4:02
mveRichard Deeming30-Sep-02 4:02 
GeneralRe: NetServerEnum Pin
Vipul Bhatt30-Sep-02 20:07
Vipul Bhatt30-Sep-02 20:07 
GeneralRe: NetServerEnum Pin
Richard Deeming30-Sep-02 23:44
mveRichard Deeming30-Sep-02 23:44 
GeneralRe: NetServerEnum Pin
Vipul Bhatt1-Oct-02 1:53
Vipul Bhatt1-Oct-02 1:53 
GeneralRe: NetServerEnum Pin
Vipul Bhatt1-Oct-02 1:57
Vipul Bhatt1-Oct-02 1:57 
GeneralRegEnumKeyEx and WinXP Pin
stefan b28-Sep-02 6:38
stefan b28-Sep-02 6:38 
GeneralRe: RegEnumKeyEx and WinXP Pin
Nick Parker28-Sep-02 17:37
protectorNick Parker28-Sep-02 17:37 
GeneralRe: RegEnumKeyEx and WinXP Pin
stefan b29-Sep-02 5:59
stefan b29-Sep-02 5:59 
QuestionHow to declare constants Pin
sybux200027-Sep-02 7:46
sybux200027-Sep-02 7:46 
AnswerRe: How to declare constants Pin
Ray Cassick27-Sep-02 7:59
Ray Cassick27-Sep-02 7:59 
Generalsimple question Pin
ns27-Sep-02 6:18
ns27-Sep-02 6:18 
GeneralRe: simple question Pin
Paul Riley27-Sep-02 6:33
Paul Riley27-Sep-02 6:33 
GeneralRe: simple question Pin
ns27-Sep-02 8:47
ns27-Sep-02 8:47 
GeneralRe: simple question Pin
Nick Parker27-Sep-02 9:12
protectorNick Parker27-Sep-02 9:12 
GeneralRe: simple question Pin
Paul Riley27-Sep-02 10:34
Paul Riley27-Sep-02 10:34 
GeneralRe: simple question Pin
Nick Parker28-Sep-02 17:39
protectorNick Parker28-Sep-02 17:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.