Hi
Firstly, I marshal array of char like so
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
internal String szShortName;
I had the same error. I declared the "pointer to a struct" as IntPtr and
when calling the API I used Marshal.AllocHGlobal, Marshal.StructureToPtr,
Marshal.PtrToStructure....
private Boolean AcmFormatEnumCallBack(Int32 driverID, ref AcmFormatDetails
formatDetails, Int32 instances, Int32 supportFlags)
{
WaveFormatEx waveFormatEx;
waveFormatEx =
(WaveFormatEx)Marshal.PtrToStructure(formatDetails.waveFormatEx,
typeof(WaveFormatEx));
List.Add(new AudioFormat(codec, formatDetails.szFormat, waveFormatEx));
return true;
}
public void Refresh()
{
Boolean driverWasOpen;
IntPtr waveFormatExBuffer;
WaveFormatEx waveFormatEx = new WaveFormatEx();
driverWasOpen = codec.IsOpen;
if (!driverWasOpen)
codec.Open();
waveFormatExBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(waveFormatEx));
try
{
List.Clear();
Marshal.StructureToPtr(waveFormatEx, waveFormatExBuffer, false);
AcmFormatDetails formatDetails = new AcmFormatDetails();
formatDetails.waveFormatEx = waveFormatExBuffer;
formatDetails.dwFormatTag = 0;
formatDetails.waveFormatExBufferSize = Marshal.SizeOf(waveFormatEx);
formatDetails.cbStruct = Marshal.SizeOf(formatDetails);
MsAcm.MMCheck(MsAcm.AcmFormatEnum(codec.Instance, ref formatDetails, new
MsAcm.AcmFormatEnumDelegate(AcmFormatEnumCallBack), 0, 0),
typeof(AudioFormatException), "Error enumerating audio formats for
codec : " + codec.ShortName);
}
finally
{
Marshal.FreeHGlobal(waveFormatExBuffer);
if (!driverWasOpen & codec.IsOpen)
codec.Close();
}
}
--
Pete
-------
Read/Write .NET articles
http://www.howtodothings.com/showarticles.asp?subcategory=132