Share via


子裝置建立

子裝置一詞是用來描述下表所列四個元件的系結。

元件 描述

Miniport 物件

公開迷你埠驅動程式 IMiniportXxx 介面的物件

Port 物件

公開端口驅動程式 IPortXxx 介面的物件

資源清單物件

物件,包含指派給子裝置的配接器驅動程式資源清單

參考字串

新增至裝置路徑名稱的名稱,以在篩選建立期間指定子裝置

子裝置的 IMiniportXxx 和 IPortXxx 介面分別繼承自基底介面 IMiniportIPort

PortCls 系統驅動程式不會區分埠驅動程式和迷你埠驅動程式。 它只需要物件,例如埠物件,其介面可以處理系統產生的要求。

同樣地,PortCls 不會直接涉及管理資源。 它只需要將要求處理常式 (埠驅動程式) 系結至資源清單。 配接器驅動程式負責將埠、迷你埠和資源清單物件系結在一起。

下列程式碼範例示範配接器驅動程式如何執行下列動作:

  //
  // Instantiate the port by calling a function supplied by PortCls.
  //
  PPORT    port;
  NTSTATUS ntStatus = PcNewPort(&port, PortClassId);

  if (NT_SUCCESS(ntStatus))
  {
      PUNKNOWN miniport;
      //
      // Create the miniport object.
      //
      if (MiniportCreate)   // a function to create a proprietary miniport
      {
          ntStatus = MiniportCreate(&miniport,
                                    MiniportClassId, NULL, NonPagedPool);
      }
      else   // Ask PortCls for one of its built-in miniports.
      {
          ntStatus = PcNewMiniport((PMINIPORT*)&miniport,
                                   MiniportClassId);
      }

      if (NT_SUCCESS(ntStatus))
      {
          //
          // Bind the port, miniport, and resources.
          //
          ntStatus = port->Init(DeviceObject,
                                Irp, miniport, UnknownAdapter, ResourceList);
          if (NT_SUCCESS(ntStatus))
          {
              //
              // Hand the port driver and the reference
              // string to PortCls.
              //
              ntStatus = PcRegisterSubdevice(DeviceObject,
                                             Name, port);
          }

          //
          // We no longer need to reference the miniport driver.
          // Either the port driver now references it,
          // or binding failed and it should be deleted.
          //
          miniport->Release();
      }

      //
      // Release the reference that existed when PcNewPort() gave us
      // the pointer in the first place. This reference must be released
      // regardless of whether the binding of the port and miniport
      // drivers succeeded.
      //
      port->Release();
  }

如需上述程式碼範例中 PortCls 函式呼叫的相關資訊,請參閱 PcNewPortPcNewMiniportPcRegisterSubdevice