public Device[] GetDevices(int deviceType) { if (!_meetingManager.IsServierStarted) { return(Device.EmptyDevices); } var deviceListPointer = IntPtr.Zero; try { int maxDeviceCount = 10, getDeviceCount = 0; var deviceInfoByte = Marshal.SizeOf(typeof(DeviceInfo)); var maxDeviceBytes = deviceInfoByte * maxDeviceCount; deviceListPointer = Marshal.AllocHGlobal(maxDeviceBytes); var result = MeetingAgent.GetDeviceList(deviceType, deviceListPointer, maxDeviceCount, ref getDeviceCount); if (result != 0) { return(Device.EmptyDevices); } Device[] devices = new Device[getDeviceCount]; for (var i = 0; i < getDeviceCount; i++) { var pointer = (IntPtr)(deviceListPointer.ToInt64() + i * deviceInfoByte); DeviceInfo deviceInfo = (DeviceInfo)Marshal.PtrToStructure(pointer, typeof(DeviceInfo)); devices[i] = new Device() { IsDefault = deviceInfo.m_isDefault == 1, Name = deviceInfo.m_szDevName }; } return(devices); } catch (Exception ex) { Log.Logger.Error($"GetDevices({deviceType}) exception:{ex}"); return(Device.EmptyDevices); } finally { if (deviceListPointer != IntPtr.Zero) { Marshal.FreeHGlobal(deviceListPointer); } } }