IWMDMNotification::WMDMMessage 方法 (mswmdm.h)
WMDMMessage 方法是客户端实现的回调方法,在连接或删除符合即插即用的设备或存储介质时,由 Windows 媒体设备管理器调用。
语法
HRESULT WMDMMessage(
[in] DWORD dwMessageType,
[in] LPCWSTR pwszCanonicalName
);
参数
[in] dwMessageType
指定消息类型的 DWORD 。
事件类型的可能值如下:
消息类型 | 说明 |
---|---|
WMDM_MSG_DEVICE_ARRIVAL | 设备已连接。 |
WMDM_MSG_DEVICE_REMOVAL | 已删除设备。 |
WMDM_MSG_MEDIA_ARRIVAL | 已将存储介质插入连接的设备中。 |
WMDM_MSG_MEDIA_REMOVAL | 已从连接的设备中删除存储介质。 |
[in] pwszCanonicalName
指向以 null 结尾的宽字符字符串的指针,该字符串指定生成此事件的设备的规范名称。 应用程序不会释放此值。
返回值
返回值是一个 HRESULT ,应用程序可在其中返回其消息处理结果。 WMDM 会忽略返回值。
注解
若要了解应用程序如何通过此方法订阅接收通知,请参阅 启用通知。
示例
以下 C++ 代码实现 WMDMMessage 方法,并输出设备或存储到达或离开通知消息。
HRESULT WMDMMessage(DWORD dwMessageType, LPCWSTR pwszCanonicalName)
{
switch(dwMessageType)
{
case WMDM_MSG_DEVICE_ARRIVAL:
// TODO: Display a message indicating that a new device has been detected and display the device name.
break;
case WMDM_MSG_DEVICE_REMOVAL:
// TODO: Display a message that the device has been removed and display the device name.
break;
case WMDM_MSG_MEDIA_ARRIVAL:
// TODO: Display a message indicating that storage media has been added to the device and display the device name.
break;
case WMDM_MSG_MEDIA_REMOVAL:
// TODO: Display a message that storage media has been removed from the device and display the device name.
break;
default:
// TODO: Display a message indicating that an unidentified message has been received.
break;
}
return S_OK; // Return value is ignored, and not returned to the application.
}
要求
要求 | 值 |
---|---|
目标平台 | Windows |
标头 | mswmdm.h |
Library | Mssachlp.lib |