Exemplo n.º 1
0
        public ICollection <CompleteRadioInfo> ListComplete()
        {
            var info = new NativeDefinitions.RadioInfo();
            var ptr  = Marshal.AllocHGlobal(info.bLength);

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

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

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

            return(count > 1 ? ListCompleteBig((int)count, structSize) : new[] { new CompleteRadioInfo(info) });
        }
Exemplo n.º 2
0
        private static ICollection <CompleteRadioInfo> ListCompleteBig(int deviceCount, int size)
        {
            var bufferSize = deviceCount * size;
            var ptr        = Marshal.AllocHGlobal(bufferSize);

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

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

            Marshal.FreeHGlobal(ptr);

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

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