This problem is driving me up the wall.

I'm using .NET 2.0 and VS2005 to work with some of the Windows Media Format
SDK through p/invoke

I've created the appropriate interfaces I need and decorated them with
ComImport, InterfaceType and Guid attributes. Specifically these interfaces
are IWMReader and IWMReaderCallback

I p/invoke the WMCreateReader method to instantiate and return an object
implementing the IWMReader interface.

The definition of this function is as follows:

[DllImport("WMVCore.dll", EntryPoint = "WMCreateReader", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int WMCreateReader(IntPtr pUnkReserved,
WMT_RIGHTS dwRights,
[Out, MarshalAs(UnmanagedType.Interface)] out IWMReader ppReader);

This gives me an object of type System.__ComObject when attempting to call
the methods implemented by the IWMReader interface I receive the following
exception:

Unable to cast COM object of type 'System.__ComObject' to interface type
'<interface name here>. This operation failed because the QueryInterface call
on the COM component for the interface with IID
'{96406BD6-2B2B-11D3-B36B-00C04F6108FF}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE)).

The offending method is the Start method, although the Open method works
perfectly.

I have seen many posts regarding this problem but as of yet have not
discovered a solution. The problem is not limited to the Windows Media
Format SDK.

The code works fine under .NET 1.1 & VS2003.

I have attached the IWMReader interface definition for reference.

[ComImport]
[Guid("96406BD6-2B2B-11d3-B36B-00C04F6108FF")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWMReader
{
void Open([In, MarshalAs(UnmanagedType.LPWStr)] string pwszURL,
[In, MarshalAs(UnmanagedType.Interface)] IWMReaderCallback
pCallback,
[In] IntPtr pvContext);
void Close();
void GetOutputCount([Out] out uint pcOutputs);
void GetOutputProps([In] uint dwOutputNum,
[Out, MarshalAs(UnmanagedType.Interface)] out
IWMOutputMediaProps ppOutput);
void SetOutputProps([In] uint dwOutputNum,
[In, MarshalAs(UnmanagedType.Interface)]
IWMOutputMediaProps pOutput);
void GetOutputFormatCount([In] uint dwOutputNumber, [Out] out uint
pcFormats);
void GetOutputFormat([In] uint dwOutputNumber,
[In] uint dwFormatNumber,
[Out, MarshalAs(UnmanagedType.Interface)] out
IWMOutputMediaProps ppProps);
void Start([In] ulong cnsStart,
[In] ulong cnsDuration,
[In] Single fRate,
[In] IntPtr pvContext);
void Stop();
void Pause();
void Resume();
}