internal static extern bool DeviceIoControl( IntPtr hDevice, uint dwIoControlCode, ref long InBuffer, int nInBufferSize, ref BTH_RADIO_INFO OutBuffer, int nOutBufferSize, out int pBytesReturned, IntPtr lpOverlapped);
private void ReadVersionsInfo() { if (_remoteVersionsInfo != null) return; #if WinXP bool success; BTH_RADIO_INFO buf; IntPtr radioHandle = BluetoothRadio.PrimaryRadio.Handle; /* * http://msdn.microsoft.com/en-us/library/ff536685(v=VS.85).aspx * The IOCTL_BTH_GET_RADIO_INFO request obtains information about the specified remote radio. * struct _BTH_RADIO_INFO { ULONGLONG lmpSupportedFeatures; USHORT mfg; USHORT lmpSubversion; UCHAR lmpVersion; */ /* * e.g. BTH_RADIO_INFO v1_2, 777, Broadcom, 00000808380DFEFF. * When no connection: INFO: IOCTL_BTH_GET_RADIO_INFO failure: 1167 = 0x48F. * 1167 = ERROR_DEVICE_NOT_CONNECTED */ //var h = this. // Windows 7 IOCTL long bthaddr = this.DeviceAddress.ToInt64();//endian? buf = new BTH_RADIO_INFO(); var len = Marshal.SizeOf(buf); int bytesReturned; success = NativeMethods.DeviceIoControl(radioHandle, NativeMethods.MsftWin32BthIOCTL.IOCTL_BTH_GET_RADIO_INFO, ref bthaddr, Marshal.SizeOf(bthaddr), ref buf, len, out bytesReturned, IntPtr.Zero); if (!success) { var gle = Marshal.GetLastWin32Error(); var ex = new System.ComponentModel.Win32Exception(); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "INFO: IOCTL_BTH_GET_RADIO_INFO failure: {0} = 0x{1:X}.", (InTheHand.Win32.Win32Error)gle, gle)); Debug.Assert(gle == ex.NativeErrorCode); throw ex; } else { _remoteVersionsInfo = buf.ConvertToRadioVersions(); } #else LmpVersion lmpVersion; UInt16 lmpSubversion; Manufacturer mfg; LmpFeatures lmpSupportedFeatures; int ret = NativeMethods.BthReadRemoteVersion( this.DeviceAddress.ToByteArrayLittleEndian(), out lmpVersion, out lmpSubversion, out mfg, out lmpSupportedFeatures); const int ERROR_SUCCESS = 0; if (ret == ERROR_SUCCESS) { _remoteVersionsInfo = new RadioVersions(lmpVersion, lmpSubversion, lmpSupportedFeatures, mfg); } else { var gle = Marshal.GetLastWin32Error(); var ex = new System.ComponentModel.Win32Exception(ret); Debug.WriteLine("BthReadRemoteVersion fail: " + ret + ", gle: " + gle); Debug.Assert(ret == gle, "WAS using gle but docs say use ret. Check that are the same."); throw ex; } #endif }