NativeMethods.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Security;
  4. namespace MediaBrowser.Common.Implementations.NetworkManagement
  5. {
  6. /// <summary>
  7. /// Class NativeMethods
  8. /// </summary>
  9. [SuppressUnmanagedCodeSecurity]
  10. public static class NativeMethods
  11. {
  12. //declare the Netapi32 : NetServerEnum method import
  13. /// <summary>
  14. /// Nets the server enum.
  15. /// </summary>
  16. /// <param name="ServerName">Name of the server.</param>
  17. /// <param name="dwLevel">The dw level.</param>
  18. /// <param name="pBuf">The p buf.</param>
  19. /// <param name="dwPrefMaxLen">The dw pref max len.</param>
  20. /// <param name="dwEntriesRead">The dw entries read.</param>
  21. /// <param name="dwTotalEntries">The dw total entries.</param>
  22. /// <param name="dwServerType">Type of the dw server.</param>
  23. /// <param name="domain">The domain.</param>
  24. /// <param name="dwResumeHandle">The dw resume handle.</param>
  25. /// <returns>System.Int32.</returns>
  26. [DllImport("Netapi32", CharSet = CharSet.Auto, SetLastError = true),
  27. SuppressUnmanagedCodeSecurity]
  28. public static extern int NetServerEnum(
  29. string ServerName, // must be null
  30. int dwLevel,
  31. ref IntPtr pBuf,
  32. int dwPrefMaxLen,
  33. out int dwEntriesRead,
  34. out int dwTotalEntries,
  35. int dwServerType,
  36. string domain, // null for login domain
  37. out int dwResumeHandle
  38. );
  39. //declare the Netapi32 : NetApiBufferFree method import
  40. /// <summary>
  41. /// Nets the API buffer free.
  42. /// </summary>
  43. /// <param name="pBuf">The p buf.</param>
  44. /// <returns>System.Int32.</returns>
  45. [DllImport("Netapi32", SetLastError = true),
  46. SuppressUnmanagedCodeSecurity]
  47. public static extern int NetApiBufferFree(
  48. IntPtr pBuf);
  49. }
  50. //create a _SERVER_INFO_100 STRUCTURE
  51. /// <summary>
  52. /// Struct _SERVER_INFO_100
  53. /// </summary>
  54. [StructLayout(LayoutKind.Sequential)]
  55. public struct _SERVER_INFO_100
  56. {
  57. /// <summary>
  58. /// The sv100_platform_id
  59. /// </summary>
  60. internal int sv100_platform_id;
  61. /// <summary>
  62. /// The sv100_name
  63. /// </summary>
  64. [MarshalAs(UnmanagedType.LPWStr)]
  65. internal string sv100_name;
  66. }
  67. }