Each Bluetooth device has a name for identifying the device to users or applications. This document shows you how to get or set device names.
The local device name
is read and set through the RHostResolver
functions GetHostName()
and SetHostName()
respectively.
Getting the Local Device Name
The following code shows how to get the local name:
Link against the following libraries:
esock.lib bluetooth.lib sdpdatabase.lib
Connect to the socket server
RSocketServ socketServ; User::LeaveIfError(socketServ.Connect()); TProtocolDesc pInfo; _LIT(KL2Cap, "L2CAP"); User::LeaveIfError(socketServ.FindProtocol(KL2Cap,pInfo));
Create and initialise
an RHostResolver
RHostResolver hr; User::LeaveIfError(hr.Open(socketServ,pInfo.iAddrFamily,pInfo.iProtocol));
Get the local device name
THostName name; TInt ret=hr.GetHostName(name);
Setting the Local Device Name
Setting the device name
differs only in the final step, where you will use the RHostResolver::SetHostName()
function.
_LIT(KDeviceName,"myDeviceName"); TInt ret=hr.SetHostName(KDeviceName);
Note:
THostName is a descriptor buffer of a suitable minimum size.