共用方式為


IMMDeviceEnumerator::RegisterEndpointNotificationCallback 方法 (mmdeviceapi.h)

RegisterEndpointNotificationCallback 方法會註冊用戶端的通知回呼介面。

語法

HRESULT RegisterEndpointNotificationCallback(
  [in] IMMNotificationClient *pClient
);

參數

[in] pClient

用戶端註冊通知回呼的 IMMNotificationClient 介面指標。

傳回值

如果方法成功,它會傳回 S_OK。 如果失敗,可能的傳回碼包括但不限於下表所示的值。

傳回碼 Description
E_POINTER
參數 pNotifyNULL
E_OUTOFMEMORY
記憶體不足。

備註

這個方法會在端點裝置的角色、狀態、存在或屬性變更時,註冊系統要呼叫的 IMMNotificationClient 介面。 呼叫端會實作 IMMNotificationClient 介面。

當不再需要通知時,用戶端可以呼叫 IMMDeviceEnumerator::UnregisterEndpointNotificationCallback 方法來終止通知。

客戶端必須確定在 RegisterEndpointNotificationCallback 呼叫之後,以及呼叫 UnregisterEndpointNotificationCallback 之前,不會釋放 IMMNotificationClient 物件。 這些方法不會呼叫用戶端的 IMMNotificationClient::AddRefIMMNotificationClient::Release 實作。 用戶端負責維護 IMMNotificationClient 對象的參考計數。 如果 RegisterEndpointNotificationCallback 呼叫成功,而且只有在呼叫 UnregisterEndpointNotificationCallback 或實作其他機制之後,用戶端才能遞增計數,以確保在呼叫 UnregisterEndpointNotificationCallback 之前不會刪除物件。 否則,應用程式會洩漏 IMMNotificationClient 所持有的資源,以及相同容器中實作的任何其他物件。

如需 AddRefRelease 方法的詳細資訊,請參閱 Windows SDK 檔中的 IUnknown 介面討論。

規格需求

需求
最低支援的用戶端 Windows Vista [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 [僅限傳統型應用程式]
目標平台 Windows
標頭 mmdeviceapi.h

另請參閱

IMMDeviceEnumerator 介面

IMMDeviceEnumerator::UnregisterEndpointNotificationCallback

IMMNotificationClient 介面