共用方式為


IWMDMStorage::SendOpaqueCommand 方法 (mswmdm.h)

SendOpaqueCommand 方法會透過 Windows Media 裝置管理員 將命令傳送至記憶體,而不需處理。

語法

HRESULT SendOpaqueCommand(
  [in, out] OPAQUECOMMAND *pCommand
);

參數

[in, out] pCommand

OPAQUECOMMAND 結構的指標,其中包含要執行的命令。 數據可以透過兩種方式傳遞:從應用程式到裝置,以及在呼叫完成時從裝置傳回應用程式。

傳回值

方法會傳回 HRESULT。 Windows Media 中的所有介面方法 裝置管理員 都可以傳回下列任何錯誤碼類別:

  • 標準 COM 錯誤碼
  • 轉換成 HRESULT 值的 Windows 錯誤碼
  • Windows Media 裝置管理員 錯誤碼
如需可能錯誤碼的廣泛清單,請參閱 錯誤碼

備註

這個方法適用於不會影響 Windows 媒體 裝置管理員 作業的儲存媒體命令,而且應該未變更傳遞。

範例

下列 C++ 程式代碼會呼叫 SendOpaqueCommand ,以對裝置執行簡單的自定義驗證步驟。 呼叫端會將其憑證和 MAC 傳送至裝置,以傳回自己的憑證和 MAC。 應用程式會比較擷取的憑證與其已儲存的憑證,如果它們符合 (且 MAC 正確) ,則會將 bExtraCertified 設定為 TRUE


    // Call SendOpaqueCommand to exchange extended authentication information.
    {
        HMAC           hMAC;
        OPAQUECOMMAND  Command;
        CERTINFOEX    *pCertInfoEx;
        DWORD          cbData_App   = sizeof(bCertInfoEx_App)/sizeof(bCertInfoEx_App[0]);
        DWORD          cbData_SP    = sizeof(bCertInfoEx_SP)/sizeof(bCertInfoEx_SP[0]);
        DWORD          cbData_Send  = sizeof(CERTINFOEX) + cbData_App;

        // Fill opaque command structure with the application's certificate.
        memcpy(&(Command.guidCommand), &guidCertInfoEx, sizeof(GUID));

        Command.pData = (BYTE *)CoTaskMemAlloc(cbData_Send);
        if (!Command.pData)
        {
            ExitOnFail(hr = E_OUTOFMEMORY);
        }
        Command.dwDataLen = cbData_Send;

        // Map the data in the opaque command to a CERTINFOEX structure, and
        // fill in the cert info to send.
        pCertInfoEx = (CERTINFOEX *)Command.pData;
        pCertInfoEx->hr     = S_OK;
        pCertInfoEx->cbCert = cbData_App;
        memcpy(pCertInfoEx->pbCert, bCertInfoEx_App, cbData_App);

        // Compute MAC on the data, and add to the OPAQUECOMMAND struct.
        g_cWmdm.m_pSAC->MACInit(&hMAC);
        g_cWmdm.m_pSAC->MACUpdate(hMAC, (BYTE*)(&(Command.guidCommand)), sizeof(GUID));
        g_cWmdm.m_pSAC->MACUpdate(hMAC, (BYTE*)(&(Command.dwDataLen)), sizeof(Command.dwDataLen));
        if (Command.pData)
        {
            g_cWmdm.m_pSAC->MACUpdate(hMAC, Command.pData, Command.dwDataLen);
        }
        g_cWmdm.m_pSAC->MACFinal(hMAC, Command.abMAC);

        // Send the opaque command.
        hr = pDevice->SendOpaqueCommand(&Command);
        if (SUCCEEDED(hr))
        {
            // Now verify the retrieved MAC.
            BYTE abMACVerify2[ WMDM_MAC_LENGTH ];
            g_cWmdm.m_pSAC->MACInit(&hMAC);
            g_cWmdm.m_pSAC->MACUpdate(hMAC, (BYTE*)(&(Command.guidCommand)), sizeof(GUID));
            g_cWmdm.m_pSAC->MACUpdate(hMAC, (BYTE*)(&(Command.dwDataLen)), sizeof(Command.dwDataLen));
            if (Command.pData)
            {
                g_cWmdm.m_pSAC->MACUpdate(hMAC, Command.pData, Command.dwDataLen);
            }
            g_cWmdm.m_pSAC->MACFinal(hMAC, abMACVerify2);

            // Verify MAC matches.
            if (memcmp(abMACVerify2, Command.abMAC, WMDM_MAC_LENGTH) == 0)
            {
                 // They match; verify the retrieved certificate.
                // Map the data in the opaque command to a CERTINFOEX structure
                //
                pCertInfoEx = (CERTINFOEX *)Command.pData;

                // In this simple extended authentication scheme, the callee must
                // provide the exact certificate information.
                //
                if ((pCertInfoEx->cbCert != cbData_SP) &&
                    (memcmp(pCertInfoEx->pbCert, bCertInfoEx_SP, cbData_SP) == 0))
                {
                    bExtraCertified = TRUE;
                }
            }
        }

        if (Command.pData)
        {
            CoTaskMemFree(Command.pData);
        }
    }

規格需求

需求
目標平台 Windows
標頭 mswmdm.h
程式庫 Mssachlp.lib

另請參閱

IWMDMStorage 介面