public static void AddPort(string portName) { var pi = new PORT_INFO_1 { Name = portName }; if (NativeMethods.AddPortEx(null, 1, ref pi, "Local Port") == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Debug.WriteLine($"Port '{portName}' added."); }
internal static extern int AddPortEx(string server, int level, [MarshalAs(UnmanagedType.Struct)] ref PORT_INFO_1 pi, string monitorName);