title: Serial port enumeration in Delphi using SetupDiGetClassDevs
body: <p>I'm trying to enumerate "friendly names" for COM ports. The ports may dynamically change as USB-serial devices are connected and disconnected at runtime.</p>
  
  <p>Based on the possible methods described in <a href="https://stackoverflow.com/questions/1205383/listing-serial-com-ports-on-windows/3018813#3018813">this question</a>, I am attempting to use the SetupDiGetClassDevs method. </p>
  
  <p>I found <a href="http://www.delphi3000.com/articles/article_4001.asp?SK=" rel="nofollow noreferrer">this example code</a>, but it is written for an older version of the setupapi unit (the original link to homepages.borland.com doesn't work of course). </p>
  
  <p>I tried using the setupapi unit from the current JVCL(<a href="http://sourceforge.net/projects/jvcl/files/JVCL%203/JVCL%203.40/JVCL340CompleteJCL221-Build3845.zip/download" rel="nofollow noreferrer">JVCL340CompleteJCL221-Build3845</a>), but it doesn't seem to be compatible with Delphi 7. I get compiler errors: </p>
  
  <pre><code>if SetupDiGetDeviceRegistryProperty(DevInfoHandle,DeviceInfoData,
      RegProperty,
      @PropertyRegDataType,
      @S1[1],RequiredSize,@RequiredSize) then begin
  </code></pre>
  
  <p>In the call to function <em>SetupDiGetDeviceRegistryProperty</em>,
  I get the error "Types of actual and formal parameters must be identical" on the parameters <em>@PropertyRegDataType</em>, and <em>@RequiredSize</em>.</p>
  
  <p>The Delphi3000 site says the code was written in 2004 and is intended for Delphi 7, so I'm not sure why it doesn't work with Delphi 7 now, unless setupapi has changed. Is anyone familiar with the changes to setupapi that could cause these problems?</p>
  
  <p>I'm testing with a simple console program. The uses statement is "  windows,
    sysutils,
    classes,
    setupAPI,
    Registry;"</p>
  
  <p>The main program is:</p>
  
  <pre><code>  begin
    ComPortStringList := SetupEnumAvailableComPorts;
    for Index := 0 to ComPortStringList.Count - 1 do
        writeln(ComPortStringList[Index]);
    end;
    end.
  </code></pre>