When doing COM interop is very important that the imported interface should match the COM one, you can always skip methods at the end or skip the parameters for the methods you are not interested in, that will work, granted:
The COM interface:
MIDL_INTERFACE("F4B1A599-7266-4319-A8CA-E70ACB11E8CD")
IAudioSessionControl : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetState(
/* [annotation][out] */
__out AudioSessionState *pRetVal) = 0;
virtual HRESULT STDMETHODCALLTYPE GetDisplayName(
/* [annotation][string][out] */
__out LPWSTR *pRetVal) = 0;
virtual HRESULT STDMETHODCALLTYPE SetDisplayName(
/* [annotation][string][in] */
__in LPCWSTR Value,
/* [unique][in] */ LPCGUID EventContext) = 0;
virtual HRESULT STDMETHODCALLTYPE GetIconPath(
/* [annotation][string][out] */
__out LPWSTR *pRetVal) = 0;
virtual HRESULT STDMETHODCALLTYPE SetIconPath(
/* [annotation][string][in] */
__in LPCWSTR Value,
/* [unique][in] */ LPCGUID EventContext) = 0;
virtual HRESULT STDMETHODCALLTYPE GetGroupingParam(
/* [annotation][out] */
__out GUID *pRetVal) = 0;
virtual HRESULT STDMETHODCALLTYPE SetGroupingParam(
/* [annotation][in] */
__in LPCGUID Override,
/* [unique][in] */ LPCGUID EventContext) = 0;
virtual HRESULT STDMETHODCALLTYPE RegisterAudioSessionNotification(
/* [annotation][in] */
__in IAudioSessionEvents *NewNotifications) = 0;
virtual HRESULT STDMETHODCALLTYPE UnregisterAudioSessionNotification(
/* [annotation][in] */
__in IAudioSessionEvents *NewNotifications) = 0;
};
Imported as:
[ComImport]
[Guid("F4B1A599-7266-4319-A8CA-E70ACB11E8CD")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioSessionControl
{
int GetState(/*ref AudioSessionState pRetVal*/);
int GetDisplayName(/*[MarshalAs(UnmanagedType.LPWStr)] ref string pRetVal*/);
int SetDisplayName(/*string Value, ref Guid EventContext*/);
int GetIconPath(/*[MarshalAs(UnmanagedType.LPWStr)] ref string pRetVal*/);
int SetIconPath(/*string Value, ref Guid EventContext*/);
int GetGroupingParam(/*ref Guid pRetVal*/);
int SetGroupingParam(/*ref Guid Override, ref Guid EventContext*/);
int RegisterAudioSessionNotification(ref IAudioSessionEvents NewNotifications);
int UnregisterAudioSessionNotification(ref IAudioSessionEvents NewNotifications);
}
Now what can you do if you are only interested in the last 2 methods? Actually not much:
[ComImport]
[Guid("F4B1A599-7266-4319-A8CA-E70ACB11E8CD")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioSessionControl
{
void _VtblGap1_7();
int RegisterAudioSessionNotification(ref IAudioSessionEvents NewNotifications);
int UnregisterAudioSessionNotification(ref IAudioSessionEvents NewNotifications);
}
This hides under a umbrella called NoPIA, part of .NET Framework 4.0