IWMDMDeviceSession::EndSession 方法 (mswmdm.h)
EndSession 方法结束设备会话。
语法
HRESULT EndSession(
[in] WMDM_SESSION_TYPE type,
[in] BYTE *pCtx,
[in] DWORD dwSizeCtx
);
参数
[in] type
描述要结束的会话类型的 WMDM_SESSION_TYPE 。 这必须是 BeginSession 中指定的值的按位 OR。
[in] pCtx
指向调用方分配的会话上下文缓冲区的可选指针,用于应用程序和服务提供商之间的专用通信。 了解基础服务提供程序的应用程序可以使用此缓冲区将特定于上下文的数据传递给它。 Windows Media 设备管理器 不对此上下文执行任何操作。 调用方负责释放此缓冲区。
[in] dwSizeCtx
上下文缓冲区的大小(以字节为单位)。 如果大小为 0,则忽略 pCtx 。 如果大小为非零, 则 pCtx 必须是有效的指针
返回值
该方法返回 HRESULT。 Windows Media 设备管理器 中的所有接口方法都可以返回以下任一类错误代码:
- 标准 COM 错误代码
- 转换为 HRESULT 值的 Windows 错误代码
- Windows Media 设备管理器错误代码
注解
会话将一组操作括起来到设备,允许 Windows Media 设备管理器 组件通过仅执行一次常见的设置和关闭功能来优化性能,而不是每次单独传输。 有关详细信息,请参阅 BeginSession。
为了响应 EndSession 调用,Windows Media 设备管理器在安全内容提供程序和服务提供商上调用 EndSession。 如果其中任一项调用失败,Windows Media 设备管理器将返回错误。 在这种情况下,对于其中一个组件, EndSession 可能会成功。
示例
以下 C++ 代码演示如何使用会话在设备上捆绑 Insert3 调用。 代码循环访问存储在向量中的多个文件,并将其发送到设备。
// Get the session interface.
CComQIPtr<IWMDMDeviceSession> pSession(pDevice);
if (pDevice == NULL)
{
// TODO: Display a message that the app wasn't able to retrieve the IWMDMDeviceSession interface.
return E_NOINTERFACE;
}
// Start the session. We don't use a custom buffer.
hr = pSession->BeginSession(WMDM_SESSION_TRANSFER_TO_DEVICE, NULL, NULL);
if (hr != S_OK)
{
/ /TODO: Display a message indicating that the session failed to start.
return hr;
}
else
{
// TODO: Display a message indicating that the session started.
}
// Insert files. These calls happen synchronously.
UINT flags = WMDM_MODE_BLOCK | WMDM_STORAGECONTROL_INSERTINTO | WMDM_FILE_CREATE_OVERWRITE | WMDM_CONTENT_FILE;
CComPtr<IWMDMStorage> pNewStorage;
for(int i = 0; i < sourceFiles.size(); i++)
{
hr = pStorageControl3->Insert3(
flags,
WMDM_FILE_ATTR_FOLDER,
sourceFiles[i],
NULL, // Use default name.
NULL, // Don't specify IWMDMOperation
NULL, // Don't specify IWMDMProgress
NULL, // Don't specify metadata
NULL, // Nothing to send to the SCP.
&pNewStorage);
if (pNewStorage != NULL)
pNewStorage.Release();
CHECK_HR(hr, "Sent file " << sourceFiles[i] << " to the device.", "Couldn't send file " << sourceFiles[i] << " to the device");
}
// Close the session.
hr = pSession->EndSession(WMDM_SESSION_TRANSFER_TO_DEVICE, NULL, NULL);
CHECK_HR(hr,"Closed the session.","Couldn't close the session.");
要求
要求 | 值 |
---|---|
目标平台 | Windows |
标头 | mswmdm.h |
Library | Mssachlp.lib |