/* LICENSE ------- Copyright (C) 2007-2010 Ray Molenkamp This source code is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this source code or the software it produces. Permission is granted to anyone to use this source code for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this source code must not be misrepresented; you must not claim that you wrote the original source code. If you use this source code in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original source code. 3. This notice may not be removed or altered from any source distribution. */ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices; using CoreAudioApi.Interfaces; namespace CoreAudioApi { [StructLayout(LayoutKind.Explicit)] public struct PropVariant { [FieldOffset(0)] short vt; [FieldOffset(2)] short wReserved1; [FieldOffset(4)] short wReserved2; [FieldOffset(6)] short wReserved3; [FieldOffset(8)] sbyte cVal; [FieldOffset(8)] byte bVal; [FieldOffset(8)] short iVal; [FieldOffset(8)] ushort uiVal; [FieldOffset(8)] int lVal; [FieldOffset(8)] uint ulVal; [FieldOffset(8)] long hVal; [FieldOffset(8)] ulong uhVal; [FieldOffset(8)] float fltVal; [FieldOffset(8)] double dblVal; [FieldOffset(8)] Blob blobVal; [FieldOffset(8)] DateTime date; [FieldOffset(8)] bool boolVal; [FieldOffset(8)] int scode; [FieldOffset(8)] System.Runtime.InteropServices.ComTypes.FILETIME filetime; [FieldOffset(8)] IntPtr everything_else; //I'm sure there is a more efficient way to do this but this works ..for now.. internal byte[] GetBlob() { byte[] Result = new byte[blobVal.Length]; for (int i = 0; i < blobVal.Length; i++) { Result[i] = Marshal.ReadByte((IntPtr) ((long)(blobVal.Data) + i)); } return Result; } public object Value { get { VarEnum ve = (VarEnum)vt; switch (ve) { case VarEnum.VT_I1: return bVal; case VarEnum.VT_I2: return iVal; case VarEnum.VT_I4: return lVal; case VarEnum.VT_I8: return hVal; case VarEnum.VT_INT: return iVal; case VarEnum.VT_UI4: return ulVal; case VarEnum.VT_LPWSTR: return Marshal.PtrToStringUni(everything_else); case VarEnum.VT_BLOB: return GetBlob(); } return "FIXME Type = " + ve.ToString(); } } } }