Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than winspool, prefix the name with the module name and a period.
EnumPorts (winspool)
.
C# S i g n a t u r e :
DllImport("winspool.drv", EntryPoint="EnumPortsA")]
static extern bool EnumPorts (string pName, int Level, IntPtr lpbPorts, int cbBuf,ref int pcbNeeded,ref int pcReturned);
VB Signature:
TODO
User-Defined Types:
None.
Alternative Managed API:
Do you know one? Please contribute it!
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct PORT_INFO_2
{
public string pPortName;
public string pMonitorName;
public string pDescription;
public PortType fPortType;
internal int Reserved;
}
[DllImport("winspool.drv", EntryPoint="EnumPortsA",SetLastError=true)]
private static extern int EnumPorts (string pName, int Level, IntPtr lpbPorts, int cbBuf,ref int pcbNeeded,ref int pcReturned);
public static PORT_INFO_2[] GetAvailablePorts()
{
return GetAvailablePorts("");
}
public static PORT_INFO_2[] GetAvailablePorts(string servername)
{
int ret;
int pcbNeeded=0; int pcReturned=0; int lastErr =0; IntPtr TempBuff=IntPtr.Zero;
PORT_INFO_2[] pinfo=null;
ret=EnumPorts(servername,2,TempBuff,0,ref pcbNeeded,ref pcReturned);
try
{
TempBuff=Marshal.AllocHGlobal(pcbNeeded+1);
ret = EnumPorts(servername, 2, TempBuff, pcbNeeded,ref pcbNeeded,ref pcReturned);
lastErr=Marshal.GetLastWin32Error();
if (ret!=0)
{
IntPtr CurrentPort =TempBuff;
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).