在VB.net类中使用IMFSourceResolver::BeginCreateObjectFromURL()
会调用IMFAsynccallback::Invoke()
方法,但是在此Invoke()方法中调用IMFSourceResolver::EndCreateObjectFromURL()
会引发System.AccessViolationException。
IMFSourceResolver的签名:
<ComImport>
<Guid("FBE5A32D-A497-4b61-BB85-97B1A848A6E3")>
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
<SuppressUnmanagedCodeSecurity>
Friend Interface IMFSourceResolver
Sub BeginCreateObjectFromURL(<[In], MarshalAs(UnmanagedType.LPWStr)> pwszURL As String, dwFlags As UInt32, <[In], MarshalAs(UnmanagedType.Interface)> pProps As IPropertyStore, <Out, MarshalAs(UnmanagedType.IUnknown)> ByRef ppIUnknownCancelCookie As Object, pCallback As IntPtr, <[In], MarshalAs(UnmanagedType.IUnknown)> punkState As Object)
<PreserveSig>
Function EndCreateObjectFromURL(pResult As IMFAsyncResult, ByRef pObjectType As Int32, <Out, MarshalAs(UnmanagedType.Interface)> ByRef ppObject As Object) As Integer
'Other methods
End Interface
IMFAsyncCallback的签名:
<ComImport>
<Guid("A27003CF-2354-4F2A-8D6A-AB7CFF15437E")>
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
<SuppressUnmanagedCodeSecurity>
Public Interface IMFAsyncCallback
<PreserveSig>
Function GetParameters(ByRef pdwFlags As UIntPtr, ByRef pdwQueue As UIntPtr) As Integer
<PreserveSig>
Function Invoke(<[In], MarshalAs(UnmanagedType.Interface)> pAsyncResult As IMFAsyncResult) As Integer
End Interface
来电者:
Dim pUnkCancelCookie As Object = Nothing
Dim pUnkThis = DirectCast(Me, IMFSourceReaderCallback)
hr = MFCreateSourceResolver(_SourceResolver)
Marshal.ThrowExceptionForHR(hr)
'Use IMFSourceReader in asynchronous mode
pAttr.SetUnknown(AudioGuids.MF_SOURCE_READER_ASYNC_CALLBACK, pUnkThis)
pAttr.SetUINT32(AudioGuids.Attributes.MF_LOW_LATENCY, 1)
_SourceResolver.BeginCreateObjectFromURL(url, SourceResolverFlags.MF_RESOLUTION_MEDIASOURCE Or SourceResolverFlags.MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE Or SourceResolverFlags.MF_RESOLUTION_READ, Nothing, pUnkCancelCookie, pCallback, Nothing)
异常的HRESULT是E_POINTER
。