Bluetooth and WSALookupServiceBegin

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

I'd like to use WSALookupServiceBegin to enumerate Bluetooth devices so
I can talk to them using Sockets - we've had unfortunate experiences
with talking to them using COM ports. However, I don't have much
experience with P/Invoking, and the descriptions for
WSALookupServiceBegin, WSAQUERYSET etc look somewhat scary.

I can't find anyone else doing this at the moment - does anyone know if
it's possible, etc?
 
Yes, I've started a Bluetooth project for OpenNETCF - you can view the code
online here. The current functionality does device id and name lookup. It's
fairly basic and is implemented synchronously returning an array of results
and this process is quite slow, however it is a stable proof of concept at
this stage. It works on all devices with the Microsoft Bluetooth stack.

Peter
 
Here's the URL, sorry I missed it out :-)

http://www.opennetcf.org/sourcebrow...netPub/wwwroot/Source/OpenNETCF.Net.Bluetooth

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Peter Foot said:
Yes, I've started a Bluetooth project for OpenNETCF - you can view the
code online here. The current functionality does device id and name
lookup. It's fairly basic and is implemented synchronously returning an
array of results and this process is quite slow, however it is a stable
proof of concept at this stage. It works on all devices with the Microsoft
Bluetooth stack.

Peter
 
Peter Foot said:
Yes, I've started a Bluetooth project for OpenNETCF - you can view the code
online here. The current functionality does device id and name lookup. It's
fairly basic and is implemented synchronously returning an array of results
and this process is quite slow, however it is a stable proof of concept at
this stage. It works on all devices with the Microsoft Bluetooth stack.

Ah, excellent. Thanks very much - I'll see what I can do with it. Does
it have any dependencies on the other OpenNETCF stuff? (We're currently
using the 1.0 libraries, and given the stage of project we're at, we
don't want to really be upgrading to 1.1 at the moment.)
 
Peter Foot said:
Yes, I've started a Bluetooth project for OpenNETCF - you can view the code
online here. The current functionality does device id and name lookup. It's
fairly basic and is implemented synchronously returning an array of results
and this process is quite slow, however it is a stable proof of concept at
this stage. It works on all devices with the Microsoft Bluetooth stack.

Just checking a bit further, having looked at the code - there doesn't
seem to be a way of creating an EndPoint (for binding a normal socket
to) from this code. Do you know how it might be done? I must admit I
don't know much about this whole area.
 
I honestly haven't got that far yet. However from reading the SDK
documentation the regular winsock APIs (connect etc) will accept a Bluetooth
specific variation of the SOCKETADDR structure, and since the managed Socket
class uses these APIs internally it should be possible to pass this data
into these (I really don't want to have to wrap the entire winsock
functionality again!). I'm creating a BluetoothSocketAddress and
BluetoothEndPoint derived from the standard SocketAddress and EndPoint
classes respectively which should facilitate this. I hope to get some time
this weekend to make some headway on this, and I'll keep the online source
updated as I progress.

Peter
 
Peter Foot said:
I honestly haven't got that far yet. However from reading the SDK
documentation the regular winsock APIs (connect etc) will accept a Bluetooth
specific variation of the SOCKETADDR structure, and since the managed Socket
class uses these APIs internally it should be possible to pass this data
into these (I really don't want to have to wrap the entire winsock
functionality again!). I'm creating a BluetoothSocketAddress and
BluetoothEndPoint derived from the standard SocketAddress and EndPoint
classes respectively which should facilitate this. I hope to get some time
this weekend to make some headway on this, and I'll keep the online source
updated as I progress.

That's great - good luck with it, and let me know if you'd like a hand.

I notice that when creating a new Bluetooth instance you're calling
WSAStartup, btw - I presume it's okay to call that more than once?
(Obviously the regular .NET sockets stuff will be calling it too.)
 
Back
Top