Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
getdefaultcommconfig (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool GetDefaultCommConfig(string lpszName, [In, Out] ref COMMCONFIG lpCC,
   ref uint lpdwSize);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

        [DllImport("kernel32.dll")]
        static extern bool GetDefaultCommConfig(string lpszName, [In, Out] ref COMMCONFIG lpCC, ref uint lpdwSize);

        [StructLayout(LayoutKind.Sequential)]
            internal struct DCB
        {
            public Int32 DCBLength;
            public Int32 BaudRate;
            public Int32 fBitField;
            public Int16 wReserved;
            public Int16 XonLim;
            public Int16 XoffLim;
            public Byte ByteSize;
            public Byte Parity;
            public Byte StopBits;
            public Char XonChar;
            public Char XoffChar;
            public Char ErrorChar;
            public Char EofChar;
            public Char EvtChar;
            public Int32 wReserved1;
        }

        [StructLayout(LayoutKind.Sequential)]
            internal struct COMMCONFIG
        {
            public Int32 dwSize;
            public Int16 wVersion;
            public Int16 wReserved;
            public DCB dcb;
            public Int32 dwProviderSubType;
            public Int32 dwProviderOffset;
            public Int32 dwProviderSize;
            public string wcProviderData;
        }

        private void ScanCommPorts(int maxComPortNumber)
        {
            COMMCONFIG cc = new COMMCONFIG();
            uint sz = (uint)Marshal.SizeOf(cc);

            for(int i=1; i<=maxComPortNumber; i++)
            {
                string comPortName = string.Format("COM{0}", i);
                bool bSuccess = GetDefaultCommConfig(comPortName, ref cc, ref sz);
                Console.WriteLine(string.Format("{0}: {1}", comPortName, bSuccess ? "Valid" : "Invalid"));
            }
        }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • 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).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions