Example #1
0
        public static BTSTATUS BT_InquireDevices(INQUIRY ucInqMode, byte ucInqTimeLen, out BLUETOOTH_DEVICE_INFO[] deviceInfos)
        {
            NativeMethods.BLUETOOTH_DEVICE_INFO DeviceInfo = new BLUETOOTH_DEVICE_INFO();
            long   DeviceInfoSize  = Marshal.SizeOf(DeviceInfo);
            int    DeviceInfoCount = 1;
            long   DeviceInfosSize = DeviceInfoCount * DeviceInfoSize;
            IntPtr DeviceInfosPtr  = Marshal.AllocHGlobal((int)DeviceInfosSize);

            // Copy the struct to unmanaged memory.
            Marshal.StructureToPtr(DeviceInfo, DeviceInfosPtr, false);
            BTSTATUS result = NativeMethods.BT_InquireDevices(
                ucInqMode,
                ucInqTimeLen,
                ref DeviceInfosSize,
                DeviceInfosPtr);

            DeviceInfoCount = (int)(DeviceInfosSize / DeviceInfoSize);

            deviceInfos = new BLUETOOTH_DEVICE_INFO[DeviceInfoCount];
            for (int i = 0; i < DeviceInfoCount; i++)
            {
                DeviceInfo     = (BLUETOOTH_DEVICE_INFO)Marshal.PtrToStructure(new IntPtr(DeviceInfosPtr.ToInt64() + i * DeviceInfoSize), typeof(BLUETOOTH_DEVICE_INFO));
                deviceInfos[i] = DeviceInfo;
            }
            return(result);
        }
Example #2
0
        public static BTSTATUS BT_InquireDevices(INQUIRY ucInqMode, byte ucInqTimeLen, out BLUETOOTH_DEVICE_INFO[] deviceInfos)
        {
            NativeMethods.BLUETOOTH_DEVICE_INFO DeviceInfo = new BLUETOOTH_DEVICE_INFO();
            long DeviceInfoSize = Marshal.SizeOf(DeviceInfo);
            int DeviceInfoCount = 1;
            long DeviceInfosSize = DeviceInfoCount * DeviceInfoSize;
            IntPtr DeviceInfosPtr = Marshal.AllocHGlobal((int)DeviceInfosSize);

            // Copy the struct to unmanaged memory.
            Marshal.StructureToPtr(DeviceInfo, DeviceInfosPtr, false);
            BTSTATUS result = NativeMethods.BT_InquireDevices(
                    ucInqMode,
                    ucInqTimeLen,
                    ref DeviceInfosSize,
                    DeviceInfosPtr);
            DeviceInfoCount = (int)(DeviceInfosSize / DeviceInfoSize);

            deviceInfos = new BLUETOOTH_DEVICE_INFO[DeviceInfoCount];
            for (int i = 0; i < DeviceInfoCount; i++)
            {
                DeviceInfo = (BLUETOOTH_DEVICE_INFO)Marshal.PtrToStructure(new IntPtr(DeviceInfosPtr.ToInt64() + i * DeviceInfoSize), typeof(BLUETOOTH_DEVICE_INFO));
                deviceInfos[i] = DeviceInfo;
            }
            return result;
        }
Example #3
0
 public static extern BTSTATUS BT_InquireDevices(
     INQUIRY ucInqMode,
     byte ucInqTimeLen,
     ref long IpDevsListLength,
     IntPtr DevsList);
Example #4
0
 public static extern BTSTATUS BT_InquireDevices(
     INQUIRY ucInqMode,
     byte ucInqTimeLen,
     ref long IpDevsListLength,
     IntPtr DevsList);