Hi,
I gotten Protected Memory Error while trying to access the C++ interface from C#, I am wandering is it something is not correct on my interpretation from C++ to C#. Below is the C++ Interface code and next to it is my C# code.
//*************** C++ Code ************************************************** ***
// {AEB23DA0-54BB-11d2-BD98-0080ADB67301}
DEFINE_GUID(IID_IAudioOutput,
0xaeb23da0, 0x54bb, 0x11d2, 0xbd, 0x98, 0x0, 0x80, 0xad, 0xb6, 0x73, 0x1);
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// The different audio output format
#ifndef _Quasar_AudioOutputType
#define _Quasar_AudioOutputType
typedef enum
{
DIGITAL_AUDIO, // Through On-board DAC
PCM_AUDIO, // Through Quasar SpDiff channel, no AC-3
AC3_AUDIO // Through Quasar SpDiff channel
} AUDIO_OUTPUT, *PAUDIO_OUTPUT;
#endif
// Audio channel
#ifndef _Quasar_AudioOutputMode
#define _Quasar_AudioOutputMode
typedef enum
{
STEREO,
LEFT_ONLY, // Right channel output on both speakers
RIGHT_ONLY // Left channel output on both speakers
} AUDIO_CHANNEL, *PAUDIO_CHANNEL;
#endif
/////////////////////////////////////////////////////////////////////////////
// interface IAudioOutput used to get/set audio output (Digital, PCM or AC3)
interface IAudioOutput : public IUnknown
{
public:
STDMETHOD(GetOutput)(PAUDIO_OUTPUT pAudioOutput) PURE;
STDMETHOD(SetOutput)(AUDIO_OUTPUT AudioOutput) PURE;
STDMETHOD(GetChannel)(PAUDIO_CHANNEL pAudioChannel) PURE;
STDMETHOD(SetChannel)(AUDIO_CHANNEL AudioChannel) PURE;
};
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//*************************************** C# Code *******************************
public enum AUDIO_OUTPUT : int
{
DIGITAL_AUDIO=0,
PCM_AUDIO=1,
AC3_AUDIO=2 // Through Quasar SpDiff channel
}
public enum AUDIO_CHANNEL : int
{
STEREO=0,
LEFT_ONLY=1,
RIGHT_ONLY=2 // Left channel output on both speakers
}
[ComVisible(true), ComImport,
Guid("AEB23DA0-54BB-11d2-BD98-0080ADB67301"),
InterfaceType(ComInterfaceType.InterfaceIsDual )]
public interface IAudioOutput
{
[PreserveSig]
int SetOutPut(AUDIO_CHANNEL pAudioOutput);
[PreserveSig]
int GetOutput([Out]out AUDIO_CHANNEL pAudioOutput);
[PreserveSig]
int SetMode(AUDIO_CHANNEL AudioMode);
[PreserveSig]
int GetMode([Out]out AUDIO_CHANNEL pAudioMode);
}