public static HResult GetEnableData(this IMFContentEnabler contentEnabler, out byte[] data) { if (contentEnabler == null) { throw new ArgumentNullException("contentEnabler"); } IntPtr dataPtr; int dataLength; HResult hr = contentEnabler.GetEnableData(out dataPtr, out dataLength); if (hr.Succeeded()) { try { data = new byte[dataLength]; Marshal.Copy(dataPtr, data, 0, dataLength); } finally { Marshal.FreeCoTaskMem(dataPtr); } } else { data = null; } return(hr); }
/////////////////////////////////////////////////////////////////////// // Name: DoNonSilentEnable // Description: Performs non-silent enable. ///////////////////////////////////////////////////////////////////////// private void DoNonSilentEnable() { // Trust status for the URL. MFURLTrustStatus trustStatus = MFURLTrustStatus.Untrusted; HResult hr; string sURL; // Enable URL int cchURL = 0; // Size of enable URL in characters. IntPtr pPostData; // Buffer to hold HTTP POST data. int cbPostDataSize = 0; // Size of buffer, in bytes. // Get the enable URL. This is where we get the enable data for non-silent enabling. hr = m_pEnabler.GetEnableURL(out sURL, out cchURL, out trustStatus); MFError.ThrowExceptionForHR(hr); Debug.WriteLine(string.Format("Content enabler: URL = {0}", sURL)); LogTrustStatus(trustStatus); if (trustStatus != MFURLTrustStatus.Trusted) { throw new COMException("The enabler URL is not trusted. Failing.", (int)HResult.E_FAIL); } // Start the thread that monitors the non-silent enable action. hr = m_pEnabler.MonitorEnable(); MFError.ThrowExceptionForHR(hr); // Get the HTTP POST data hr = m_pEnabler.GetEnableData(out pPostData, out cbPostDataSize); MFError.ThrowExceptionForHR(hr); try { WebHelper m_webHelper = new WebHelper(); // Open the URL and send the HTTP POST data. m_webHelper.OpenURLWithData(sURL, pPostData, cbPostDataSize, m_hwnd); } finally { Marshal.FreeCoTaskMem(pPostData); } }