Example #1
0
        public ICollection <RadioInfo> List()
        {
            var info = new NativeDefinitions.RadioInfo2();
            var ptr  = Marshal.AllocHGlobal((int)info.bLength);

            var structSize = 0;
            var count      = G313Api.GetRadioList(ptr, (int)info.bLength, ref structSize);

            if (info.bLength != structSize)
            {
                throw new InvalidOperationException("info size mismatch");
            }

            Marshal.PtrToStructure(ptr, info);
            Marshal.FreeHGlobal(ptr);

            return(count > 1 ? ListBig(count, structSize) : new[] { new RadioInfo(info) });
        }
Example #2
0
        private static ICollection <RadioInfo> ListBig(int deviceCount, int size)
        {
            var bufferSize = deviceCount * size;
            var ptr        = Marshal.AllocHGlobal(bufferSize);

            var structSize = 0;

            var count = G313Api.GetRadioList(ptr, bufferSize, ref structSize);

            var buffer = ToManagedStructure <NativeDefinitions.RadioInfo2>(ptr, structSize, count);

            Marshal.FreeHGlobal(ptr);

            if (count != deviceCount)
            {
                throw new InvalidOperationException("device count mismatch!");
            }

            return(buffer.Select(raw => new RadioInfo(raw)).ToArray());
        }