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); }
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)); }
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); }
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; }