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_ConnectService(BLUETOOTH_DEVICE_INFO DeviceInfo, GENERAL_SERVICE_INFO ServiceInfo, ref int lpConnectionHandle)
        {
            int    DeviceInfoSize = Marshal.SizeOf(DeviceInfo);
            IntPtr DeviceInfoPtr  = Marshal.AllocHGlobal(DeviceInfoSize);

            Marshal.StructureToPtr(DeviceInfo, DeviceInfoPtr, false);

            int    ServiceInfoSize = Marshal.SizeOf(ServiceInfo);
            IntPtr ServiceInfoPtr  = Marshal.AllocHGlobal(ServiceInfoSize);

            Marshal.StructureToPtr(ServiceInfo, ServiceInfoPtr, false);

            return(BT_ConnectService(DeviceInfoPtr, ServiceInfoPtr, IntPtr.Zero, ref lpConnectionHandle));
        }
Esempio n. 3
0
        public static BTSTATUS BT_ConnectService(BLUETOOTH_DEVICE_INFO DeviceInfo, GENERAL_SERVICE_INFO ServiceInfo, ref int lpConnectionHandle)
        {
            int DeviceInfoSize = Marshal.SizeOf(DeviceInfo);
            IntPtr DeviceInfoPtr = Marshal.AllocHGlobal(DeviceInfoSize);
            Marshal.StructureToPtr(DeviceInfo, DeviceInfoPtr, false);

            int ServiceInfoSize = Marshal.SizeOf(ServiceInfo);
            IntPtr ServiceInfoPtr = Marshal.AllocHGlobal(ServiceInfoSize);
            Marshal.StructureToPtr(ServiceInfo, ServiceInfoPtr, false);

            return BT_ConnectService(DeviceInfoPtr, ServiceInfoPtr, IntPtr.Zero, ref lpConnectionHandle);
        }
Esempio n. 4
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;
        }