Error 126 for GetDefaultCommConfig on Windows 10

Category: windows hardware wdk and driver development


RouzaudBenjamin on Mon, 13 Nov 2017 16:56:39

Hello everyone,

I am using 'GetDefaultCommConfig' function to enumerate all active COM ports in a C++ project.

On previous W7E version, I receive 'ERROR_SUCCESS' for all active COM Ports, and error 87 for all other ports.

On Windows IoT, I receive error 126 for all active COM Ports, and error 87 for all other ports.

Any idea on how to fix it?

Thanks in advance!


Brian Catlin on Mon, 13 Nov 2017 20:30:04

Error 126 is ERROR_MOD_NOT_FOUND. Are you certain that this API is supported on IoT?


Doron Holan [MSFT] on Mon, 13 Nov 2017 20:56:54

GetDefaultCommConfig is not supported on IoT. The most durable solution is to enumerate instances of the serial port device interface. This also allows you to know about serial ports dynamically arriving. The second best solution is to enumerate the SERIALCOMM key

RouzaudBenjamin on Wed, 15 Nov 2017 15:30:02

Thank you very much for your answer

shekhar_s on Tue, 26 Feb 2019 11:28:53

I am using below code in printer driver for accessing port . But GetDefaultCommConfig failing with error 87 on windows 10, 64 bit. Please help resolving issue. 

void C_PORT_MONITOR::SetPrinterComPortParam(LPTSTR   PortName)

#ifdef _UNICODE
std::wstring   l_ComPortName;
std::string    l_ComPortName;
    DWORD dwSize,le = 0;
 dwSize = sizeof(COMMCONFIG);
 lpCC->dwSize = sizeof(COMMCONFIG);
 lpCC->wVersion = 1;
 l_ComPortName = PortName;//mPortName; 
    if(l_ComPortName.length() <= 0 )
 bool SetFlag = false;
  //Get COMM port params called to get size of config. block
 int length = l_ComPortName.length();
 int iPos = l_ComPortName.find(':'); //In windows viata port name is coming differentl
 //Ori_//int iPos = l_ComPortName.find_of_first(':'); //In windows viata port name is coming differentl
 int iChc = length - iPos; //remove the charactrers after :
 _RPT1(_CRT_WARN, " b4 GetDefaultCommConfig l_ComPortName. = %S \n",;
 l_ComPortName = l_ComPortName.substr(0, iPos);
 //Get COMM port params with defined size
 _RPT1(_CRT_WARN, "C_PORT_MONITOR::SetPrinterComPortParam length=%x,iPos=%x,iChc=%x,l_ComPortName=%S",length, iPos, iChc, l_ComPortName.c_str());
 //l_ComPortName = l_ComPortName.substr(0, iPos);
 BOOL ret = GetDefaultCommConfig(l_ComPortName.c_str(), lpCC, &dwSize);
 _RPT1(_CRT_WARN, "C_PORT_MONITOR::SetPrinterComPortParam l_ComPortName=%S,l_ComPortName.c_str()= %S \n",, l_ComPortName.c_str());
  le = GetLastError();
  _RPT1(_CRT_WARN ,"C_PORT_MONITOR::SetPrinterComPortParam LastError=%x\n",le);