Also, when using the connect function I get an error and -1 is returned,
but the message says that the operation was completed successfully. Why
is that?
Z.K.
output:
Successful Opening Socket
result = ╠╠╠╠╠╠╠╠╠00:20:e0:7f:12:07
status = -1
error:
The operation completed successfully.
error:
The operation completed successfully.
code:
SOCKADDR_BTH addr;
memset(&addr,0,sizeof(addr));
int status = 0;
int s = 0;
char BTAddress[18] = "00:20:e0:7f:12:07";
addr.addressFamily = AF_BTH;
addr.port = BT_PORT_ANY;
addr.btAddr = 0;
WSAStringToAddress(BTAddress,AF_BTH,NULL,(LPSOCKADDR)&addr,(LPINT)64);
char result[1];
WSAAddressToString((LPSOCKADDR)&addr,(DWORD)sizeof(addr),NULL,result,(LPDWORD)sizeof(result));
printf("\nresult = %s\n",result);
//connect to server
status = connect(s, (SOCKADDR*)&addr, sizeof(SOCKADDR_BTH));
//send a message
if(status == 0)
MessageBox(NULL,"Sucess Connecting to Socket","Connect Dialog",MB_OK);
else
{
printf("status = %d\n",status);
MessageBox(NULL,"Error Connecting to Socket","Connect Dialog",MB_OK);
PrintLastError();
}
void PrintLastError(void)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM|
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), 0, (LPTSTR) &lpMsgBuf,
0, NULL);
fprintf(stderr, "\n\nerror: \n%s\n", lpMsgBuf);
printf("\n\nerror: \n%s\n", lpMsgBuf);
CString temp;
temp.Format("%s",lpMsgBuf);
MessageBox(NULL,temp,"Error Dialog",MB_OK);
}
void sometest(void)
{
SOCKADDR_IN addr = {0};
int status = 0;
int s = 0;
char BTAddress[18] = "192.168.0.13";
char result[64] = {0};
DWORD dwSizeOfStr = sizeof(result);
int nSizeOfInput = sizeof(addr);
addr.sin_family = AF_INET;
status = WSAStringToAddressA(BTAddress, AF_INET, NULL, (LPSOCKADDR)&addr,
&nSizeOfInput);
if (status == 0)
{
status = WSAAddressToStringA((LPSOCKADDR)&addr, nSizeOfInput, NULL,
result, &dwSizeOfStr);
printf("\nresult = %s\n",result);
}
}
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
"Z.K." <nos...@nospam.net> wrote in message
news:emeLW1Zg...@TK2MSFTNGP02.phx.gbl...
>I am trying to make a Bluetooth application and I am using sockets with
>RFCOMM. I have pased some code and the output below. I hard code a
>Bluetooth MAC address then use WSAStringToAddress and WSAAddressToString
>afterwards to make sure it is correct. I get a bunch of garbage at the
>start of result and I am not sure why.
>
> Also, when using the connect function I get an error and -1 is returned,
> but the message says that the operation was completed successfully. Why
> is that?
>
> Z.K.
>
> output:
>
> Successful Opening Socket
> result = ąąąąąąąąą00:20:e0:7f:12:07
Z.K.