GetDefaultCommConfig is returning error 87 (ERROR_INVALID_PARAMETER) RRS feed

  • Question

  • I am implementing a serial driver for the serial ports on my PCI-e controller. I am testing the serial IO APIs using this driver. 

    I am writing the devicename string (\device\serialx) into SERIALCOMM registry. 

    THe API SEtDefaultCommConfig is passing without any problems. However the API GetDefaultCOmmCOnfig fails with error 87(ERROR_INVALID_PARAMETER). 

    I am calling this API in the below way.


    1. I have checked in my system that a port with name COM1 exists and it is working. 

    2. I tried initializing the dwSize member of CommCOnfig structure to size of COMMCONFIG structure.

    3. In DwSize i am passing the size of the COMMCONFIG structure. 

    4. I am running the application with Administrator privileges. 

    I am calling SetDefaultCommCOnfig in a more or less similar way as above it is working properly. But GetDefaultCommCOnfig is failing...What could be the reason behind this? 

    • Edited by pramod ky Tuesday, July 29, 2014 3:46 PM Rephrased the question
    Tuesday, July 29, 2014 3:44 PM

All replies

  • what specifically are you writing to the SERIALCOMM key? the key name must be the COM port name and exactly match the string you pass to GetDefaultCommConfig, ie "COM1" : REG_SZ "\device\serial0"

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, July 29, 2014 8:31 PM
  • 2. I tried initializing the dwSize member of CommCOnfig structure to size of COMMCONFIG structure.

    3. In DwSize i am passing the size of the COMMCONFIG structure.

    Pass a larger buffer.  The last member of COMMCONFIG is a variable sized array.

    -- pa

    Wednesday, July 30, 2014 12:50 AM
  • I got the same problem with Windows 10.
    Look like someone has found the problem insider the usbser.sys driver.

    But you have this problem with your own driver, not usbser?

    IIRC the usbser issue was caused by missing double terminating 0 in the reg_multi_sz value that it writes to the registry. This causes the registry read function in KMDF library to fail. (So maybe when MS fixes the usbser.sys, they may by the same opportunity modify the registry read module in KMDF to be more robust: if terminating zeros in a multi_sz value are missing, just append them in memory and keep going. This would prevent any such issue in future).


    -- pa

    • Edited by Pavel A Tuesday, January 5, 2016 11:24 AM
    • Proposed as answer by Robert.My Tuesday, January 5, 2016 11:38 AM
    Tuesday, January 5, 2016 11:22 AM
  • Hi Everyone,

    Am facing the same issue that GetdafaultCommConfig() function is failing with last error 57. I am using a miniport printer driver,in which am trying to Set Printer COM Port Parameter. In the function SetPrinterComPortParam() am getting the portname as LPTSTR type Variable. And I was using that variable to initialize to wstring,so that I can do some string operation to trim my port name to "COMx". The substring which I got after trimming can be used as input parameter to GetdafaultCommConfig() as a 1st argument. But the function is failing with the last error 57.Am not sure whats wrong with the parameters. Can someone suggest me on this issue.

    Below is the code snippet.

    void C_PORT_MONITOR::SetPrinterComPortParam(LPTSTR   PortName)
    #ifdef _UNICODE
    std::wstring   l_ComPortName;
    std::string    l_ComPortName;
        DWORD dwSize,le = 0;
       dwSize = sizeof(COMMCONFIG);

        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_first_of(':'); //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 = l_ComPortName.substr(0, (length - iChc)); //remove the characters from colon  //COM1


     //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);

      l_ComPortName = l_ComPortName.substr(0, (length - iChc));

     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, l_ComPortName.c_str());

      le = GetLastError();
      _RPT1(_CRT_WARN ,"C_PORT_MONITOR::SetPrinterComPortParam LastError=%x\n",le);

    Friday, February 15, 2019 6:36 AM