共用方式為


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
程式庫 Mssachlp.lib

另請參閱

IWMDMDeviceSession 介面

IWMDMDeviceSession::BeginSession

WMDM_SESSION_TYPE