Esempio n. 1
0
        public static BTSTATUS BT_BrowseServices(BLUETOOTH_DEVICE_INFO DeviceInfo, bool bBrowseAllServices, out GENERAL_SERVICE_INFO[] ServiceInfos)
        {
            int    DeviceInfoSize = Marshal.SizeOf(DeviceInfo);
            IntPtr DeviceInfoPtr  = Marshal.AllocHGlobal(DeviceInfoSize);

            Marshal.StructureToPtr(DeviceInfo, DeviceInfoPtr, false);

            GENERAL_SERVICE_INFO ServiceInfo = new GENERAL_SERVICE_INFO();
            int    ServiceInfoCount          = 16;
            int    ServiceInfoSize           = Marshal.SizeOf(ServiceInfo);
            int    ServiceInfosSize          = ServiceInfoSize * ServiceInfoCount;
            IntPtr ServiceInfosPtr           = Marshal.AllocHGlobal(ServiceInfosSize);

            Marshal.StructureToPtr(ServiceInfo, ServiceInfosPtr, false);

            ServiceInfoCount = 0;

            BTSTATUS result = NativeMethods.BT_BrowseServices(
                DeviceInfoPtr,
                bBrowseAllServices,
                ref ServiceInfosSize,
                ServiceInfosPtr);

            ServiceInfoCount = ServiceInfosSize / ServiceInfoSize;

            ServiceInfos = new GENERAL_SERVICE_INFO[ServiceInfoCount];
            for (int i = 0; i < ServiceInfoCount; i++)
            {
                ServiceInfos[i] = (GENERAL_SERVICE_INFO)Marshal.PtrToStructure(new IntPtr(ServiceInfosPtr.ToInt64() + i * ServiceInfoSize), typeof(GENERAL_SERVICE_INFO));
            }
            return(result);
        }
Esempio n. 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);
        }