want to use vb6 for discovering bluetooth devices (cellular phones) in area and then sending vnotes to them. I use winsock and ws2 .. Please tell me how can I discover phones and send a message to them shortly. thanks by now. Please send me a short vb example for this.. or tell me a book name or site address please. I really need it.
I use wsalookupservicestart but vb6 is crashing when I try to use this function. My source code is :
Private Const ERROR_SUCCESS = 0
Private Const INVALID_SOCKET = 0
Private Const MIN_SOCKETS_REQD As Long = 1
Private Const WS_VERSION_REQD As Long = &H202
Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
Private Const AF_BTH = 32
Private Const PF_BTH = 32
Private Const NS_BTH = 16
Private Const BTHPROTO_RFCOMM = 3
Private Function HiByte(ByVal wParam As Integer)
HiByte = wParam \ &H100 And &HFF&
End Function
Private Function LoByte(ByVal wParam As Integer)
LoByte = wParam And &HFF&
End Function
Private Sub SocketsCleanup()
If WSACleanup() <> ERROR_SUCCESS Then
MsgBox "Socket error occurred in Cleanup."
End If
End Sub
Private Function SocketsInitialize() As Boolean
Dim WSAD As WSADATA
Dim sLoByte As String
Dim sHiByte As String
If WSAStartup(WS_VERSION_REQD
, WSAD) <> ERROR_SUCCESS Then
MsgBox "The 32-bit Windows Socket is not responding."
SocketsInitialize = False
Exit Function
End If
If LoByte(WS_VERSION_REQD) < 2 Then
If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
MsgBox "This application requires a minimum of " & CStr(MIN_SOCKETS_REQD) & " supported sockets."
SocketsInitialize = False
Exit Function
End If
End If
If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
sHiByte = CStr(HiByte(WSAD.wVersion)
)
sLoByte = CStr(LoByte(WSAD.wVersion)
)
MsgBox "Sockets version " & sLoByte & "." & sHiByte & " is not supported by 32-bit Windows Sockets."
SocketsInitialize = False
Exit Function
End If
'must be OK, so lets do it
MsgBox "Sozkets Initialized"
SocketsInitialize = True
End Function
Public Function Find_First_BT() As Boolean
Dim BTH_Query As WSAQUERYSET
Dim Next_Handle As Long
Dim BTH_Lookup_Flags As Long
Dim Bth_Socket_Num As Long
If SocketsInitialize = False Then
SocketsCleanup
MsgBox "Error Opening Socket for Bluetooth"
Find_First_BT = False
Exit Function
End If
Bth_Socket_Num = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM)
If Bth_Socket_Num = INVALID_SOCKET Then
SocketsCleanup
MsgBox "Error :INVALID_SOCKET on opening a Socket for Bluetooth"
Find_First_BT = False
Exit Function
End If
' WSACleanup
'BTH_Query.dwNameSpace = 0
BTH_Query.dwNameSpace = NS_BTH
BTH_Query.dwSize = Len(BTH_Query)
BTH_Query.dwNumberOfCsAddr
s = 0
BTH_Query.lpafpProtocols.i
AddressFam
ily = AF_BTH
BTH_Query.lpafpProtocols.i
Protocol = BTHPROTO_RFCOMM
'GoTo ATLA
BTH_Query.lpServiceClassId
.Data1 = &H1105
BTH_Query.lpServiceClassId
.Data2 = &H0
BTH_Query.lpServiceClassId
.Data3 = &H1000
BTH_Query.lpServiceClassId
.Data4(0) = &H80
BTH_Query.lpServiceClassId
.Data4(1) = &H0
BTH_Query.lpServiceClassId
.Data4(2) = &H0
BTH_Query.lpServiceClassId
.Data4(3) = &H80
BTH_Query.lpServiceClassId
.Data4(4) = &H5F
BTH_Query.lpServiceClassId
.Data4(5) = &H9B
BTH_Query.lpServiceClassId
.Data4(6) = &H34
BTH_Query.lpServiceClassId
.Data4(7) = &HFB
ATLA:
BTH_Lookup_Flags = LUP_CONTAINERS Or LUP_RETURN_ADDR Or LUP_RETURN_NAME Or LUP_FLUSHCACHE
MsgBox "About to scan for BT devices"
result = WSALookupServiceBegin(BTH_
Query, BTH_Lookup_Flags, Next_Handle)
MsgBox "Done first step in scan for BT devices"
If result = SOCKET_ERROR Then
SocketsCleanup
result = closesocket(Bth_Socket_Num
)
MsgBox "Error calling WSALookupServiceBegin"
Find_First_BT = False
Exit Function
End If
result = closesocket(Bth_Socket_Num
)
SocketsCleanup
End Function
Private Sub Command1_Click()
Find_First_BT
End Sub
' --------------------------
I use a winsock module for functions and other types and stuff.