Implementing and Registering a Port Supplier

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Implementing and Registering a Port Supplier.

The role of a port supplier is to track and supply ports, which in turn manage processes. At the time a port needs to be created, the port supplier is instantiated using CoCreate with the port supplier's GUID (the session debug manager [SDM] will use the port supplier the user selected or the port supplier specified by the project system). The SDM will then call CanAddPort to see if any ports can be added. If a port can be added, a new port is requested by calling AddPort and passing it an IDebugPortRequest2 that describes the port. AddPort will return a new port represented by an IDebugPort2 interface.

A port is created by a port supplier, which is in turn associated with a machine or debug server. A server can enumerate its port suppliers through theEnumPortSuppliers method, and a port supplier can enumerate its ports through the EnumPorts method.

In addition to the typical COM registration, a port supplier must register itself with Visual Studio by placing its CLSID and name in specific registry locations. A Debugging SDK helper function called SetMetric handles this chore: it is called once for each item to be registered, thus:

SetMetric(metrictypePortSupplier,  
          <GUID of your port supplier>,  
          metricCLSID,  
          <CLSID of your port supplier>,  
          false,  
          NULL)  
SetMetric(metrictypePortSupplier,  
          <GUID of your port supplier>,  
          metricName,  
          <name of your port supplier>,  
          false,  
          NULL);  

A port supplier unregisters itself by calling RemoveMetric (another Debugging SDK helper function) once for each item that was registered, thus:

RemoveMetric(metrictypePortSupplier,  
             <GUID of your port supplier>,  
             metricCLSID,  
             NULL);  
RemoveMetric(metrictypePortSupplier,  
             <GUID of your port supplier>,  
             metricName,  
             NULL);  

System_CAPS_ICON_note.jpg Note

The SDK Helpers for DebuggingSetMetric and RemoveMetric are static functions defined in dbgmetric.h and compiled into ad2de.lib. The metrictypePortSupplier, metricCLSID, and metricName helpers are also defined in dbgmetric.h.

A port supplier can supply its name and GUID through the methods GetPortSupplierName and GetPortSupplierId, respectively.

Implementing a Port Supplier
SDK Helpers for Debugging
Port Suppliers

Show: