Hi!
I have a code, which can discover devices, and return their name and addresses. That's fine. But I can't estabilish a connection... Here is the code:
(I had intialize Winsock, and opened a Bluetooth socket. The device discovery works, and the LUP_RETURN_ADDR flag is set at the WSALookupServiceNext)
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
-------
...
unsigned short addressAsString[1000];
DWORD addressSize = sizeof(addressAsString);
addressSize = sizeof (addressAsString);
if (0==WSAAddressToString(pws
aResults->
lpcsaBuffe
r->RemoteA
ddr.lpSock
addr, pwsaResults->lpcsaBuffer->
RemoteAddr
.iSockaddr
Length, &protocolInfo, addressAsString, &addressSize))
{
MessageBox(hDlg, _T("Convert complete"), _T("WSAAddressToString"), MB_OK);
if (pwsaResults->lpcsaBuffer)
{
SendMessage(GetDlgItem(hDl
g, IDC_DEVLIST),
LB_ADDSTRING,
0,
(LPARAM)pwsaResults->lpcsa
Buffer->Re
moteAddr.l
pSockaddr)
;
}
}
else
{
MessageBox(hDlg, _T("Convert incomplete"), _T("WSAAddressToString"), MB_OK);
}
SOCKADDR_BTH address;
memset (&address, 0, sizeof(address));
address.addressFamily = AF_BTH;
address.btAddr = 0; //pwsaResults->lpcsaBuffer
->RemoteAd
dr.lpSocka
ddr;
address.port = BT_PORT_ANY;
sockaddr *pAddr = (sockaddr *)&address;
if (0!= bind(s, pAddr, sizeof(SOCKADDR_BTH)))
{
MessageBox(hDlg, _T("bind sikertelen!"), _T("BIND"), MB_OK);
}
if (0 != connect(s, pAddr, sizeof(SOCKADDR_BTH)))
{
MessageBox(hDlg, _T("nem sikerült kapcsolódni") , _T("connection failed"), MB_OK);
}
else
{
MessageBox(hDlg, _T("Kapcsolódva!"), _T("AFTER BIND/CONNECT"), MB_OK);
}
...
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
-------
In all three cases (WSAAddressToString, bind and connect) I get to the ELSE, so all of them unsuccsessful. In the case of the WSAAddressToString I don't really know what can be the problem, but when thinking about bind and connect I'm pretty sure that somethings wrong with the SOCKADDR_BTH structure, becouse I miss the "address.serviceClassId = ". That's becouse that I can't give them a valid value? I tried GUID_NULL, but don't worked.
Maybe I'm on a totally wrong way... What is your suggestion, about this? How can I connect to a device, which I have it's name and address using Winsock functios?
(I don't know if it's a problem or not, but I use only LUP_CONTAINERS at WSALookupServiceBegin, and LUP_RETURN_NAME | LUP_RETURN_ADDR at WSALookupServiceNext)
Thanks in advance,
AndreW
Start Free Trial