Need Help - NetServerEnum compile error 
Author Message
 Need Help - NetServerEnum compile error

Ihad found the article which can find sql server
connections but there are some compile error:

1) Unsafe code may only appear if compiling with /unsafe
2) No overload for method 'StructLayoutAttribute'
takes '0' arguments
3) 'System.Runtime.InteropServices.LayoutKind' does not
contain a defintion for 'sequential'
4) 'System.Runtime.InteropServices.CharSet' does not
contain a definition for 'auto'

What does all those errors mean? Thank you.

The C# code which i copy from Visual Studio .Net EA Everett
using System;
using System.Runtime.InteropServices;

namespace Test_Out_SQL_Conn
        /// <summary>
        /// Summary description for sqlservers.
        /// </summary>
        public class sqlservers
                public sqlservers()
                        // TODO: Add constructor logic here

                        private static extern uint
CopyMemory( [MarshalAs(UnmanagedType.AsAny)] object
object Source,
                        int length);

                        unsafe private static extern uint
NetServerEnum([MarshalAs(UnmanagedType.LPWStr)] string
                        uint level,
                        uint* bufptr,
                        uint prefmaxlen,
                        ref uint entriesread,
                        ref uint totalentries,
                        uint servertype,
string domain,
                        uint resume_handle);

te (LayoutKind.sequential,]
                        private struct SERVER_INFO_101
                        public int dwPlatformID;
                        public System.IntPtr
                        public int dwVersionMajor;
                        public int dwVersionMinor;
                        public int dwType;
                        public int lpszComment;

                private static ServerTypeEnum _serverType;

                public static ServerTypeEnum ServerType
                                return _serverType;
                                _serverType = value;

                public static string[] GetList(string
                        string[] servers;
                        string serverName = null;
                        string domainName = domain;
                        uint level = 101, prefmaxlen =
0xFFFFFFFF, entriesread = 0, totalentries = 0;
                        uint resume_handle = 0;

                                        // get a pointer
to the server info structure
si = null;
pTmp;   // temp pointer for use when loopingthrough
returned (pointer) array
                                        // this api
requires a pointer to a byte array..which is actually a
pointer to an array
                                        uint nRes =
NetServerEnum(serverName, level, (uint *) &si, prefmaxlen,
ref entriesread, ref totalentries, (uint)_serverType,
domainName, resume_handle);
                                        servers = new
                                        if (nRes == 0)
                                                if ((pTmp
= si) != null)

        for (int i = 0; i < entriesread; i++)



                servers[i] = Marshal.PtrToStringAuto(pTmp-



        catch(Exception e)


                string error = e.Message;


                        catch(Exception /*e*/)
                                return null;
                        return servers;


        public enum ServerTypeEnum : uint
                None = 0,
                ALL = 0xFFFFFFFF,
                WORKSTATION = 0x00000001,
                SERVER = 0x00000002,
                SQLSERVER = 0x00000004,
                DOMAIN_CTRL = 0x00000008,
                DOMAIN_BAKCTRL = 0x00000010,
                TIME_SOURCE = 0x00000020,
                AFP = 0x00000040,
                NOVELL = 0x00000080,
                DOMAIN_MEMBER = 0x00000100,
                PRINTQ_SERVER = 0x00000200,
                DIALIN_SERVER = 0x00000400,
                XENIX_SERVER = 0x00000800,
                NT = 0x00001000,
                WFW = 0x00002000,
                SERVER_MFPN = 0x00004000,
                SERVER_NT = 0x00008000,
                POTENTIAL_BROWSER = 0x00010000,
                BACKUP_BROWSER = 0x00020000,
                MASTER_BROWSER = 0x00040000,
                DOMAIN_MASTER = 0x00080000,
                SERVER_OSF = 0x00100000,
                SERVER_VMS = 0x00200000,
                WINDOWS = 0x00400000,   /* Windows 95 and
above */
                DFS = 0x00800000,               /* Root of
a DFS tree */
                CLUSTER_NT = 0x01000000,        /* NT
Clusters */
                DCE = 0x10000000,       /* IBM DSS
(Directory and Security Services) or equivalent */
                ALTERNATE_XPORT = 0x20000000,   /* Return
list of alternate transport */
                LOCAL_LIST_ONLY = 0x40000000,   /* Return
local list only */
                DOMAIN_ENUM = 0x80000000


Chua Wen Ching

Tue, 17 May 2005 11:00:38 GMT  
 Need Help - NetServerEnum compile error
Chua Wen Ching,

>1) Unsafe code may only appear if compiling with /unsafe

Compile with /unsafe option.

>2) No overload for method 'StructLayoutAttribute'
>takes '0' arguments
>3) 'System.Runtime.InteropServices.LayoutKind' does not
>contain a defintion for 'sequential'
>4) 'System.Runtime.InteropServices.CharSet' does not
>contain a definition for 'auto'

C# is case sensitive. Make sure you get the case right for all
members. It should be Sequential and Auto.

You should also free the returned buffer with NetApiBufferFree().


Please reply only to the newsgroup.

Tue, 17 May 2005 14:43:47 GMT  
 Need Help - NetServerEnum compile error
to compile unsafe code in visual studio:
1) goto project properties
2) Goto configuration properties
3) under build, set Allow Unsafe Code Blocks to true
that will let ya build with unsafe blocks

> How can i compile in Visual Studio .Net with the
> option /unsafe? Do you ask me to compile with command
> prompt or???

> Thank you.

> Regards,
> Chua Wen Ching :D

Tue, 17 May 2005 18:03:49 GMT  
 Need Help - NetServerEnum compile error

> I try to compile with visual studio .net 2003 command
> prompt by typing:

> csc /unsafe sqlservers.cs

> but it end up with an error:
> error CS5001: Program 'C:/.../sqlservers.exe' does not
> have an entry point defined.

> What does this error mean?

It means that you don't have an appropriate Main() method defined.

If replying to the group, please do not mail me too

Tue, 17 May 2005 18:23:18 GMT  
 Need Help - NetServerEnum compile error
Chua Wen Ching,

>Oh i see. But i only want to create that sqlserver class
>and use it into my windows forms. So i need to put a
>temporary main in it?

No, you can compile it to a class library DLL that you can then
reference from your Winforms project.

Regarding NetApiBufferFree, you can declare and call it like this

unsafe static extern uint NetApiBufferFree(void* Buffer);




Please reply only to the newsgroup.

Tue, 17 May 2005 19:50:25 GMT  
 [ 5 post ] 

 Relevant Pages 

1. Compile Error=> Need help from expert

2. Need help w/ compile error

3. Need help with compile error

4. compiling error, need help

5. VC 5.0 Compile Errors (compiles fine with 4.2)

6. need help compiling vc++6 project in vC++.Net

7. TIME FUNCTION -- NEED help compiling

8. I need help on this compile warning message..

9. HELP: Need Help on Error (Undefined Symbol...)

10. HELP: Need Help on Error (Undefined Symbol...)

11. Need Help compiling M

12. Need Help compiling Microsoft C with Borland C


Powered by phpBB® Forum Software