Share via


Stack-Events Handling Sample (Windows Embedded CE 6.0)

1/6/2010

The BtNotify sample test application illustrates the use of message queue to handle event notifications received from the Bluetooth stack, and displays event data on the device.

The compiled sample generates a BtNotify.exe.

Usage

btnotify.exe

Btnotify sets up a message queue to receive events from the stack. The following code sample is an excerpt from this sample application which uses CreateMsgQueue to create a message queue.

HANDLE hMsgQ = CreateMsgQueue(NULL, &mqOptions);
if (! hMsgQ) {
wprintf(L"Error creating message queue.\r\n");
goto exit;
}

After the queue is created, the application calls RequestBluetoothNotifications to subscribe to events that notify about changes in connections, pairing, device, and the core stack. It uses the following event classes:

  • BTE_CLASS_CONNECTIONS
  • BTE_CLASS_PAIRING
  • BTE_CLASS_DEVICE
  • BTE_CLASS_STACK

When the stack starts sending notifications to peer Bluetooth device, the application reads the messages in the queue by calling the ReadMsgQueue function. Event data is received in the BTEVENT structure, and BTEVENT.baEventData is parsed to display information about the event.

BOOL fRet = ReadMsgQueue (hMsgQ, &btEvent, sizeof(BTEVENT), &dwBytesRead, 10, &dwFlags);
if (! fRet) 
{
  wprintf(L"Error - Failed to read message from queue!\r\n");
  goto exit;
} 
else 
{
  wprintf(L"----------------------------------------\r\n");
  wprintf(L"Got event with id=%d.\r\n", btEvent.dwEventId);
  DumpBuff(L"", btEvent.baEventData, sizeof(btEvent.baEventData));
  ParseEvent(&btEvent);
}

Remarks

When the specified number of messages is read from the queue, the applications stops receiving notifications from the stack by calling the StopBluetoothNotifications function.

For more information about event handling, see Handling Events from the Bluetooth Stack.

Sample Location

**%_WINCEROOT%*\*Public\Common\Sdk\Samples\Bluetooth\BtNotify

Note

This sample application has not been thoroughly tested and is not intended for production use.

See Also

Concepts

Bluetooth Application Development Samples
Bluetooth Samples

Other Resources

Bluetooth Application Development