. NET Compact framework BASICS (8)

Source: Internet
Author: User

This article describes how to enable and disable Bluetooth. In subsequent articles, we will describe how to use Bluetooth for file transmission.

Because the WM simulator does not support Bluetooth debugging, If You Want To debug the code, debug it on a real device.

Enabling/disabling Bluetooth depends on one API (bthsetmode in bthutil. dll)

There are three Bluetooth modes:
Poweroff turn off Bluetooth/connectable turn on Bluetooth/discoverable turn on Bluetooth and can be found.
Differences between connectable and discoverable:
Connectable: Although Bluetooth is enabled, it cannot be found for Bluetooth devices enabled later than it.
Discoverable: enables Bluetooth and can be detected by other devices.

Main Code:

1 bluetoothmode mode;
2
3 Switch (this. combobox1.selectedindex)
4 {
5 case 0:
6 mode = effecthmode. poweroff;
7 break;
8 Case 1:
9 mode = systthmode. connectable;
10 break;
11 case 2:
12 mode = descrithmode. discoverable;
13 break;
14 default:
15 mode = effecthmode. poweroff;
16 break;
17}
18
19 int result = bthsetmode (mode );
20 if (result! = 0)
21 MessageBox. Show (string. Format ("error: {0}", Marshal. getlastwin32error (). tostring ()));
22 else
23 getdomainthstatue ();

API Definition

1 [dllimport ("bthutil. dll", setlasterror = true)]
2 public static extern int bthsetmode (effecthmode dwmode );
3
4 [dllimport ("bthutil. dll", setlasterror = true)]
5 public static extern int bthgetmode (out of memory thmode dwmode );

 

At this point, a simple bluetooth device controller can be implemented. The demo is relatively simple and provides inspiration to beginners.

Download the code: devicebluw.thdemo.rar

Author: appleseeker

Date: 2008-09-15

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.