June 22, 2003

Bluetooth sockets


This morning I decided to investigate the Windows XP SP1 Bluetooth support. I played with the BluetoothXXXX API and quickly became disapointed. I then moved on to looking at how to access the Bluetooth hardware using Winsock and decided that is a much better route to take...

The Bluetooth API that lives in Irprops.cpl appears to be the easy way in to Bluetooth. The API itself has an 'interesting' design, but I can kinda understand why it looks like it does. Unfortunately it's very limited in what it offers to the developer. Basically it's an API on to the wireless link control panel applet - the fact that it lives in the same dll should have given that away... Once you realise that's all it is then it's quite good. You can programatically control all of the stuff that the control panel applet lets you do and pop up their standard dialogs, etc. So, if you want to search for devices and enumerate the 'dialup network service' then it's fine. If you want to do more then it's not for you...

Accessing Bluetooth hardware using Winsock is more cumbersome, but it looks like you can do pretty much everything you'd want to. This morning I spent some time knocking up a simple 'MSDN style' sample that iterated devices and services. It works nicely, once you understand what you're supposed to do. And you get back all of the services that your devices offer and details of the ports that they're being offered on. Since I didn't have net access I didn't go and look up the specs over at www.bluetooth.com but that's on the list for this week. The docs imply that you can register a service profile and then just listen on a socket in the usual winsock way to wait for connections, sounds cool and easy. Should be fun...
// blue.cpp : Defines the entry point for the console application.
//

#include <winsock2.h>
#include <Ws2bth.h>
#include <BluetoothAPIs.h>

#include <stdio.h>

#pragma comment(lib, "ws2_32.lib")

#pragma comment(lib, "irprops.lib")

TCHAR *GetLastErrorMessage(DWORD last_error)
{
   static TCHAR errmsg[512];

   if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 
      0,
      last_error,
      0,
      errmsg, 
      511,
      NULL))
   {
      /* if we fail, call ourself to find out why and return that error */
      return (GetLastErrorMessage(GetLastError()));  
   }
  
   return errmsg;
}
BOOL __stdcall callback(
  ULONG uAttribId,
  LPBYTE pValueStream,
  ULONG cbStreamSize,
  LPVOID pvParam)
{
//   printf("Callback %d\n", uAttribId);

   SDP_ELEMENT_DATA element;

   if (ERROR_SUCCESS != BluetoothSdpGetElementData(pValueStream,  cbStreamSize, &element))
   {
	   printf("%s\n", GetLastErrorMessage(GetLastError()));
   }


   return true;
}



int main(int argc, char* argv[])
{
   WORD wVersionRequested = 0x202;
   WSADATA m_data;

   if (0 == ::WSAStartup(wVersionRequested, &m_data))
   {
      SOCKET s = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); 

      const DWORD lastError = ::GetLastError();

      if (s == INVALID_SOCKET)
      {
	      printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));
         exit(1);
      }

      WSAPROTOCOL_INFO protocolInfo;

      int protocolInfoSize = sizeof(protocolInfo);

      if (0 != getsockopt(s, SOL_SOCKET, SO_PROTOCOL_INFO, (char*)&protocolInfo, &protocolInfoSize))
      {
         exit(1);
      }

      
      WSAQUERYSET querySet;

      memset(&querySet, 0, sizeof(querySet));

      querySet.dwSize = sizeof(querySet);

      querySet.dwNameSpace = NS_BTH;

      HANDLE hLookup;
      DWORD flags = LUP_RETURN_NAME | LUP_CONTAINERS | LUP_RETURN_ADDR | LUP_FLUSHCACHE | LUP_RETURN_TYPE | LUP_RETURN_BLOB | LUP_RES_SERVICE;

      int result = WSALookupServiceBegin(&querySet, flags, &hLookup);

      if (0 == result)
      {
         while (0 == result)
         {
            BYTE buffer[1000];

            DWORD bufferLength = sizeof(buffer);

            WSAQUERYSET *pResults = (WSAQUERYSET*)&buffer;

            result = WSALookupServiceNext(hLookup, flags, &bufferLength, pResults);

            if (result != 0)
            {
               printf("%s\n", GetLastErrorMessage(GetLastError()));
               printf("%d\n", bufferLength);
            }
            else
            {
               printf("%s\n", pResults->lpszServiceInstanceName);

               CSADDR_INFO *pCSAddr = (CSADDR_INFO *)pResults->lpcsaBuffer;

               BTH_DEVICE_INFO *pDeviceInfo = (BTH_DEVICE_INFO*)pResults->lpBlob;

               WSAQUERYSET querySet2;

               memset(&querySet2, 0, sizeof(querySet2));

               querySet2.dwSize = sizeof(querySet2);

               GUID protocol = L2CAP_PROTOCOL_UUID;

               querySet2.lpServiceClassId = &protocol;
   
               querySet2.dwNameSpace = NS_BTH;

               char addressAsString[1000];

               DWORD addressSize = sizeof(addressAsString);

               addressSize = sizeof(addressAsString);

               if (0 == WSAAddressToString(pCSAddr->LocalAddr.lpSockaddr, pCSAddr->LocalAddr.iSockaddrLength, &protocolInfo, addressAsString, &addressSize))
               {  
                  printf("local address: %s\n", addressAsString);
               }

               addressSize = sizeof(addressAsString);

               if (0 == WSAAddressToString(pCSAddr->RemoteAddr.lpSockaddr, pCSAddr->RemoteAddr.iSockaddrLength, &protocolInfo, addressAsString, &addressSize))
               {
                  printf("device address: %s\n", addressAsString);
               }




               querySet2.lpszContext = addressAsString;

               HANDLE hLookup2;
               DWORD flags = LUP_FLUSHCACHE |LUP_RETURN_NAME | LUP_RETURN_TYPE | LUP_RETURN_ADDR | LUP_RETURN_BLOB | LUP_RETURN_COMMENT;

               int result = WSALookupServiceBegin(&querySet2, flags, &hLookup2);

               if (0 == result)
               {
                  while (0 == result)
                  {
                     BYTE buffer[2000];

                     DWORD bufferLength = sizeof(buffer);

                     WSAQUERYSET *pResults = (WSAQUERYSET*)&buffer;

                     result = WSALookupServiceNext(hLookup2, flags, &bufferLength, pResults);

                     if (result != 0)
                     {
                        printf("%s\n", GetLastErrorMessage(GetLastError()));
                        printf("%d\n", bufferLength);
                     }
                     else
                     {
                        printf("%s\n", pResults->lpszServiceInstanceName);
                        //printf("%s\n", pResults->lpszComment);

                        CSADDR_INFO *pCSAddr = (CSADDR_INFO *)pResults->lpcsaBuffer;

                        addressSize = sizeof(addressAsString);

                        if (0 == WSAAddressToString(pCSAddr->LocalAddr.lpSockaddr, pCSAddr->LocalAddr.iSockaddrLength, &protocolInfo, addressAsString, &addressSize))
                        {  
                           printf("local address: %s\n", addressAsString);
                        }

                        addressSize = sizeof(addressAsString);

                        if (0 == WSAAddressToString(pCSAddr->RemoteAddr.lpSockaddr, pCSAddr->RemoteAddr.iSockaddrLength, &protocolInfo, addressAsString, &addressSize))
                        {
                           printf("device address: %s\n", addressAsString);
                        }

                        if (pResults->lpBlob)
                        {
                           const BLOB *pBlob = (BLOB*)pResults->lpBlob;

                           if (!BluetoothSdpEnumAttributes(pBlob->pBlobData, pBlob->cbSize, callback, 0))
                           {
                              printf("BluetoothSdpEnumAttributes - %s\n", GetLastErrorMessage(GetLastError()));
                           }

                        }

                     }
                  }
         
                  result = WSALookupServiceEnd(hLookup2);

               }
               else
               {
                  printf("%s\n", GetLastErrorMessage(GetLastError()));
               }

            }
         }
         
         result = WSALookupServiceEnd(hLookup);
      }
      else
      {
         printf("%s\n", GetLastErrorMessage(GetLastError()));
      }

      WSACleanup();
   }

   HANDLE hRadio;
   BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) };

   HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio( &btfrp, &hRadio );
   if ( NULL != hFind )
   {
      printf("hFind\n");

      do
      {
         //
         //  TODO: Do something with the radio handle.
         //

		 BLUETOOTH_RADIO_INFO radioInfo;

		 radioInfo.dwSize = sizeof(radioInfo);

		 if (ERROR_SUCCESS == BluetoothGetRadioInfo(hRadio, &radioInfo))
		 {
			wprintf(L"Raido: %s\n", radioInfo.szName);
		 }

		 BLUETOOTH_DEVICE_INFO_STRUCT deviceInfo;

		 deviceInfo.dwSize = sizeof(deviceInfo);

		 BLUETOOTH_DEVICE_SEARCH_PARAMS deviceSearchParams;

		 memset(&deviceSearchParams, 0, sizeof(deviceSearchParams));

		 deviceSearchParams.dwSize = sizeof(deviceSearchParams);

		 //deviceSearchParams.fReturnAuthenticated = true;
		 deviceSearchParams.fReturnRemembered = true;
		 //deviceSearchParams.fReturnUnknown = true;
		 //deviceSearchParams.fReturnConnected = true;

		 deviceSearchParams.hRadio = hRadio;

		 HANDLE hDeviceFind = BluetoothFindFirstDevice(&deviceSearchParams, &deviceInfo);

		 if (NULL != hDeviceFind)
		 {
			 do
			 {
				 wprintf(L"Device: %s\n", deviceInfo.szName);

				 //BluetoothDisplayDeviceProperties(0, &deviceInfo);
			 }
			 while(BluetoothFindNextDevice(hDeviceFind, &deviceInfo));

			 BluetoothFindDeviceClose(hDeviceFind);
		 }


		 if (BluetoothGetDeviceInfo(hRadio, &deviceInfo))
		 {
			wprintf(L"+ Device: %s\n", deviceInfo.szName);

			// BluetoothUpdateDeviceRecord - change name

			// BluetoothRemoveDevice

		 }

		 GUID guidServices[10];

		 DWORD numServices = sizeof(guidServices);

		 DWORD result = BluetoothEnumerateInstalledServices(hRadio, &deviceInfo, &numServices, guidServices);

		          CloseHandle( hRadio );
      } while( BluetoothFindNextRadio( hFind, &hRadio ) );

      BluetoothFindRadioClose( hFind );
   }


	return 0;
}

Share this entry: Email it! | bookmark it! | digg it! | reddit!

Posted by Len at June 22, 2003 08:34 PM | Comments (430) | Categories : Geek Speak , Source Code
Comments

Len

Many thanks for posting the Bluetooth Sockets code on your webpage as is is extremely useful in the bluetooth client-server application I am currently developing.

However I am having a problem in that I get an unresolved symbol for _L2CAP_PROTOCOL_UUID, so please could you identify which library this is declared in, and where I might be able to find documentation on it?

Many thanks again as I have been having many problems in getting my bluetooth code working (so far I have not got it going yet) so all the help I can get is appreciated

john

Posted by: John Puddy at July 30, 2003 01:08 PM

I'll take a look at the code at the weekend and find out where it links it in from.

Posted by: Len at July 31, 2003 10:50 PM

(Answer to the previous question is: The symbol is probably in library Uuid.lib.)

Very interesting sample. I also tried to work with bluetooth and use MS Bluetooth API and this is probably only page on net, where BluetoothFindFirstRadio function is used.
However, I have still problems with this function and also with using sockets. After running your sample I get error
"Failed to get bluetooth socket! An address incompatible with the requested protocol was used."
and alse the second part (BluetoothFindFirstRadio ...) works weird - it finds no radios despite the fact, that I have Win XP SP1 + Bluetooth QFE and Windows normally recognizes my cellular phone and can communicat with that.

Please, if you or any reader, know the answer, why this is happening, post it here.
Thank you.

Posted by: Vit Kovalcik at August 6, 2003 08:42 AM

Thanks Len,

it helped me alot taken first steps into Bluetooth communication. After applying your sample, i was able to send my first message via bluetooth.

Ronald.

Posted by: Ronald Nölte at August 26, 2003 09:04 AM

len

Thanks for identifying which library the symbol was in and you will be pleased to hear that the code now compiles and executes.

However the socket s returns INVALID_SOCKET and the application therefore fails. I have tried establishing a simple socket connection but this also fails.

Do you have any idea why this might be failing, and why I am having problems with the socket?

Thanks

Posted by: at August 26, 2003 04:50 PM

What does GetLastError() or GetLastErrorMessage() (shown above) return? As far as I know you need to have bluetooth hardware that is directly supported by XP to get this to work...

Posted by: Len at August 26, 2003 04:55 PM

Len

I think this boils down to a hardware compatability issue with Windows as I am using a 3Com USB dongle to provide Bluetooth services.

Please could you let me know which operating system and Bluetooth hardware you are using?

John

Posted by: John at September 1, 2003 02:54 PM

John,

For this code to work you MUST have hardware that is supported and recognised natively by XP SP1. I'm using XP SP1 and the built in bluetooth hardware that comes with the Sony Vaio PCG-Z1SP.

See http://www.lenholgate.com/archives/000089.html for my complaints about the difficulty in finding hardware that's compatible (I also have a TDK USB dongle which doesnt work with XPs bluetooth support)

Posted by: Len at September 1, 2003 03:31 PM

Help...great confusion!!
I've win Xp sp1 and Digicom USB dongle...
Can I use c++ code (like that one shown here)?

Thanks of all

Posted by: FastFuri at September 9, 2003 12:01 AM

Help...great confusion!!
I've win Xp sp1, Platform SDK, Visual Studio .net and Digicom USB dongle...
Can I use c++ code (like that one shown here)?

Thanks of all

Posted by: FastFuri at September 9, 2003 12:01 AM

Do you have a bluetooth tab on your wireless link control panel applet?

Does it work? If the bluetooth device is recognised by xp then you should have the tab and you should be able to do stuff with your bluetooth device via the tab. If you dont then the code above wont work.

Posted by: Len at September 9, 2003 07:52 AM

I'm sorry for my ingnorance...but I can't understand you. :°(
My wireless link in control panel works well, I think It's software written by Widcomm...but I can't understand what do you mean about tab!
Please help me soon...

Thanks of all

Posted by: FastFuri at September 9, 2003 08:50 AM

As far as I know it will only work if XP recognises your bluetooth device and doesnt need additional drivers. I have a TDK dongle that needs its own drivers and doesnt integrate with XP's wireless link control panel applet and that doesnt work with the code above. I have built in bluetooth on the Sony Vaio and that integrates with XP's control panel applet and works with the code above. That's all I know. Compile the code, see if it works.

Posted by: Len at September 9, 2003 09:06 AM

Len

Hi, after trying out the blue.c code, I also got the "Failed to get bluetooth socket! An address incompatible with the requested protocol was used" message that Vit encountered. I wonder whether you encounter the same kind of problem when you use the non-winxp compatible bluetooth device that you had? For my bluetooth device, it's a csr usb bluetooth endpoint.

Thank you and hopefully you have some thoughts on this.

Allen

Posted by: Allen at September 10, 2003 06:38 AM

Allen,

Yes, I get that error message if I run the code on my XP SP1 machine with the TDK dongle.

The TDK device doesn't seem to be supported by XP directly yet. I think their bluetooth stuff is done by Widcomm and I think you need to purchase an SDK from Widcomm to be able to programatically control it...

Posted by: Len at September 10, 2003 07:46 AM

I think it coul be helpful make a sort of list of BT device native recognized by win xp sp 1.
I'm start here with my device:

Digicom USB Palladio with Chipset CSR frimware version 373 not supported

Please, insert your experiences

Posted by: FastFuri at September 10, 2003 05:49 PM

Does anyone know if the Microsoft bluetooth adapter that comes with the MS bluetooth desktop is XP-compatible? Or any other compatible bluetooth adapters? With my AmbiCom BT2000C-USB adapter I get the error "Failed to get bluetooth socket! An address incompatible with the requested protocol was used"...

Eirik

Posted by: Eirik at September 18, 2003 02:52 AM

thanks for that code.
it compiled fine after I downloaded the latest windows platform SDK.
HOWEVER, when running the program, i get an error (translated from german):
procedure entry point "BluetoothFindNextRadio" was not found in DLL "irprops.cpl".

does anybody know what that means?
has anybody has similar problems?
thx

Posted by: slomoman at October 3, 2003 11:29 AM

That means that you dont have the correct version of the irprops.cpl control panel applet. This means that the native XP SP 1 bluetooth support isnt installed which in turn means that your hardware doesnt work with the code shown in the article.

Posted by: Len at October 3, 2003 12:36 PM

Len,
great code, but my hardware is unsupported, sigh
:-((
I've a question:
Why you create a SOCKET and get its options ?
It's only to get a string translation of addresses or is necessary to start using WSALookupServiceXXX functions ?

Max

Posted by: Max at October 7, 2003 09:16 AM

> Why you create a SOCKET and get its options ?

No reason. The code just grew and never got cleaned up. The socket creation at the start is a good way to tell if it's going to work, if that fails then your hardware isn't supported... I probably grabbed the socket options to work something out and then never removed the call...

Posted by: Len at October 7, 2003 10:42 AM

Does anyone know how to get Ws2bth.h and BluetoothAPIs.h ??? I have installed WIN XP SP1,Visual Studio .NET I have even Q323183_WXP_SP2_X86_ENU.exe but I could't find those files. I anyone could help I would be appreciate.

Posted by: Suicider at October 13, 2003 02:09 PM

Platform SDK?

Posted by: Len at October 13, 2003 02:46 PM

Hi,
I have CSR chip based Bluetooth USB dongle and iPAQ 3870 with built-in Bluetooth.

I tried your code on WIN XP and it shows all the services offered by iPAQ.i also tried other bluetooth functions from Platform SDK and all works fine.

I want my desktop with WIN XP to act as server for BLuetooth client-server communication.

I am able to open bluetooth socket and advertise SPP service on WIN XP. iPaq discovers it but when i try to connect to SPP on WIN XP, it says "Unable to connect to device" same happens when i try to connect to File Transfer Service.
On WIN XP, my application is waiting on accept().. it never accepts any call.

When i try to connect from WIN XP to iPAQ to SPP using bluetooth Sockets, it works fine.. i am able to connect it and also i can send data to iPAQ using send(), but again when i try to receive data from iPAQ using recv(), my application on WIN XP waits on recv(), but never receive any data..

i tried on WIN 98 and used createfile() to open COM4 to receive data from iPAQ to check if iPAQ is sending data or not and i receivec data on WIN 98, so my application on iPAQ is working fine.

Can you help me or tell me, why i am not able to accept incoming connections or receive data on WIN XP. i have installed everything, Platform SDK, MS Bluetooth Stack, QFE 323183.

Thanks and Regards,
Deepak

Posted by: Deepak at October 13, 2003 07:13 PM

I get a connection accepted if I advertise the service like this:

SOCKADDR_BTH address;

address.addressFamily = AF_BTH;
address.btAddr = 0;
address.serviceClassId = GUID_NULL;
address.port = BT_PORT_ANY;

sockaddr *pAddr = (sockaddr*)&address;

if (0 != bind(s, pAddr, sizeof(SOCKADDR_BTH)))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

int size = sizeof(SOCKADDR_BTH);

if (0 != getsockname(s, pAddr, &size))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

if (0 != listen(s, 10))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}


WSAQUERYSET service;

memset(&service, 0, sizeof(service));

service.dwSize = sizeof(service);

service.lpszServiceInstanceName = "My Service";
service.lpszComment = "My comment";

GUID serviceID = OBEXFileTransferServiceClass_UUID;

service.lpServiceClassId = &serviceID;

service.dwNumberOfCsAddrs = 1;
service.dwNameSpace = NS_BTH;

CSADDR_INFO csAddr;

memset(&csAddr, 0, sizeof(csAddr));

csAddr.LocalAddr.iSockaddrLength = sizeof(SOCKADDR_BTH);
csAddr.LocalAddr.lpSockaddr = pAddr;

csAddr.iSocketType = SOCK_STREAM;
csAddr.iProtocol = BTHPROTO_RFCOMM;

service.lpcsaBuffer = &csAddr;

if (0 != WSASetService(&service, RNRSERVICE_REGISTER, 0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

SOCKET s1 = accept(s, 0, 0);

unsigned char buffer[2000];

memset(buffer, 0, sizeof(buffer));

int r = recv(s1,(char*)buffer, sizeof(buffer), 0);

printf("%s\n", DumpData(buffer, r, 40).c_str());

HandlePacket(s1, r, buffer);

memset(buffer, 0, sizeof(buffer));

r = recv(s1,(char*)buffer, sizeof(buffer), 0);

printf("%s\n", DumpData(buffer, r, 40).c_str());

closesocket(s1);

if (0 != WSASetService(&service, RNRSERVICE_DELETE, 0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

closesocket(s);

WSACleanup();
}

Posted by: Len at October 13, 2003 08:54 PM

Visual C++

Posted by: Suicider at October 14, 2003 03:38 PM

No, I meant have you downloaded and installed the latest plaform sdk? (or installed it from MSDN)

Posted by: Len at October 14, 2003 04:49 PM

Hi,
I tried this code, but same thing happened,it waits on accept and never accepts any request..
Is the problem with my Dongle??
Deepak

Posted by: Deepak at October 14, 2003 06:08 PM

I've no idea. It works fine for me...

Posted by: Len at October 14, 2003 07:22 PM

Can you tell me which BT USB adapter or Dongle you are using?
Or Can you tell me what all BT Adapters are fully supported by MS BLUETOOTH API's.
I will buy that one and try it.
Thanks.
Deepak

Posted by: Deepak at October 17, 2003 07:36 AM

I have whatever is built in to my Sony Vaio. That works fine. I have a TDK dongle and that doesnt work.

Posted by: Len at October 17, 2003 08:01 AM

I have tried DBlink's DBT 120 USB adapter and Belkin USB adapter..both of the are not working.

Posted by: swarna at October 21, 2003 06:58 PM

Have anyone resolve the problem about INVALID_SOCKET?
I have the same problem that Vit Kovalcik. Could any one help me?
I have the MS SDK installed. MAy be a problem with any dll?
Thanks

Posted by: Nacho at October 24, 2003 04:51 PM

The reason you get an INVALID_SOCKET error is because you dont have appropriate drivers installed for your device. Read the comments here and on the other bluetooth entry.

Posted by: Len at October 24, 2003 05:01 PM

Is there any USB Bluetooth dongle that will work with Microsofts API for Bluetooth? While reading this, it seems, that there is a API which isn't supported by most of the manufacturers.
The actual Bluetooth .inf file from Microsoft should recognize about 12 different Bluetooth devices, but i'm not sure if these devices also are working correctly with the API. Does anyone know more?

Posted by: gawain at October 26, 2003 07:04 PM

Is there any way to connect to L2CAP layer on Microsoft BT stack ?? Because when I'm trying to make a socket "socket(AF_BTH,SOCK_STREAM, BTHPROTO_L2CAP);" But in bluetoothapis.h there is a definition of BTHPROTO_L2CAP and RFCOMM. So my quastion is: Is there any way to make a socket to L2CAP layer ?

Posted by: Suicider at October 27, 2003 09:42 AM

Can I run your application without QFE 323183?
I can install that.

Posted by: Nacho at October 27, 2003 12:30 PM

I've no idea, the bluetooth hardware in my Vaio just works and I never bothered to try and get my non functioning TDK dongle to work.

Posted by: Len at October 27, 2003 01:18 PM

In the .inf file there is an entry for sony built-in devices, but there is also an entry for a tdk device (driver expected soon since 3 month).
What about the Widcomm Bluetooth stack? Are there any header files, that can be downloaded with out buying the hole development kit?

Posted by: Gawain at October 27, 2003 02:53 PM

I've tried your code and it worked flawlessly once and the other times it gave me "The parameter is incorrect" errors even though it managed to discover the local and remote device address.

I'm currently using the USB Bluetooth Adapter that came with the Microsoft Bluetooth Mouse. For some odd reason, if the mouse is not connected, the program would fail to discover even the local address. Once it is connected, it discovers both remote and local address. This makes no sense since the adapter itself should contain an address. Furthermore, even when I set the serviceClassId to OBEXFileTransfer_UUID, it still returns the mouse's remote address!

The one time that I managed to successfully do it was in the presense of another Bluetooth laptop. Do you think that was the reason? If so, then I would be relieved because my project involves laptop to laptop communications anyways.

Quite confused and frustrated by Microsoft. Anyone know of another adapter that uses the MS Bluetooth stack? The only reason I brought the mouse is because I knew MS would definitely use their own stack.

Posted by: Hang Cheng at October 29, 2003 05:38 AM

I do have XP Professional SP1 but I can't seem to find irprops.cpl. This seems to be a common issue. Where do you get the file ?

Posted by: Alan at November 3, 2003 01:53 AM

The correct irprops.cpl for bluetooth use comes with bluetooth devices that are supported by MS's drivers. If you dont have a supported device you cant use the bluetooth functionality.

Posted by: Len at November 3, 2003 07:51 AM

hi!
I need help!!
I try test Bluetooth API in Windows XP SP1, but drivers for my dongle not are compatible with BlueTooth API. The dongle is MSI USB MS-6967 compatible Windows® 2000/ME/98/XP :(

You can recommend another device compatible with WinXP SP1 BlueTooth API ?

Thanks.

Posted by: Jose at November 3, 2003 09:31 AM

Anyone has a 10050 error (A socket operation encountered a dead network.) when executing "bind". May be a problem with the support of my device? I have a Dell TrueMobile 300, and it´s no supported by Windows XP (I think)

Posted by: Nacho at November 3, 2003 10:17 AM

Len, could you tell me what hardware, software, devices, and operating system do you have?
Is necessary to include any "*.lib" or "*.dll" of the Bluetooth adapter in the compiler?
Thank you very much.

Posted by: Nacho at November 4, 2003 04:07 PM

Windows XP SP 1.
Sony Vaio PCG-Z1SP with whatever built in Bluetooth hardware that has.
Platform SDK.

Posted by: Len at November 4, 2003 05:52 PM

Len - Thanks for your help and puting up with all us "dongles" who keep pelting you with questions :) Here's what I have gleaned so far: if the dongle isn't directly supported by M$, this code and the Bluetooth API ain't gonna work. Even if the dongle is supported by M$, it might not work (such as the TDK device). I have a D-Link DBT-120 which doesn't work with this code. The driver is written by Widcom and I'm guessing I'd have to get their SDK to control it. Fine.

Which devices work with the OS out of the box without the need for buying someone's SDK ? You have stated that your TDK doesn't work. What does work ? Who has had success and what devices were they using ?

Thanks

Posted by: Alan at November 6, 2003 02:38 AM

There is an USB adaptor that seems to work with this code. It´s Brain Boxes BL-554. I haven´t probed it yet, but they say that it can be programmed with MS SDK and is supported by MS Bluetooth Stack.
Len, could you tell me what Bluetooth adapter has your Sony Vaio? I tried in sony web but I couldn,t find it. Do you have an USB dongle of sony too?
Thanks for all.

Posted by: Nacho at November 6, 2003 12:11 PM

Len,

I'm trying to communicate from my PC to the Bluetooth enabled printer through the BTH socket programming(using RFCOMM protocol).

Currently in our application, in case of USB, transfer of a file is happening through the Symbolic link and we are transferring chunks of data of length 2048 bytes through this symbolic link.

Now I need to replace the entire USB communication to Bluetooth connection.

I need to know how can I tranfer a file in chunks of 2048 bytes, which is as similar to sending through USB port using device's symbolic link.

I'm able to create a BTH socket and binding it with the device address and now I need to communicate with the printer by sending chunks of data of 2048 bytes of a file(Just like through symboli link in USB).

I need to know what is the equivalent of symbolic link is this RFCOMM specification and how do I tranfer the data to the printer.

Awaiting response eagerly.

Thanks in advance for your help.

Posted by: Motive at November 6, 2003 12:18 PM

Nacho

Will check when I get back to the office.

Motive

I think you need to read up on socket programming. Using sockets with bluetooth isnt much different than using them in any other way.

Posted by: Len at November 6, 2003 12:25 PM

Thanks Len

Posted by: Nacho at November 6, 2003 12:28 PM

Unfortunately there isnt that much information. The bluetooth device is listed as a 'Sony USB Bluetooth device". It's built in to the laptop so there's nothing to look at :( The advanced tab of the device properties page for the device says that it has a Manufacturer Id of 10, HCI version 1, revision 525. LMP version 1, subversion 525. It's using the microsoft driver version 5.1.2535.0

Posted by: Len at November 6, 2003 07:08 PM

I have talked with TDK about their USB Bluetooth Adaptor and they said me that it may be programmed with MS SDK. I´m not sure about this becouse you say that this device doesn´t work with the code above. Your TDK device is Adaptor or Adaptor+. I have to buy one USB Bluetooth device that can be programmed with MS SDK and I don´t know witch to choose.
Len, thanks for your help and pacience

Posted by: Nacho at November 7, 2003 03:24 PM

I think TDK are selling a windows xp driver upgrade for their devices; I remember seeing it on their web page at one point and was surprised that they wanted 20 quid for it... I originally found the page via a link from one of the bluetooth newsgroups, but I forget which one.

Posted by: Len at November 7, 2003 05:39 PM

I have a 10108 error when executed the code above. This error occurs in WSALookupService Begin. I have an unsupported hardware but I can create a socket. Is it normal?

Posted by: Nacho at November 11, 2003 04:34 PM

I also have a 10050 error in bind function. Is all of this caused by an unapropiate hardware? Thanks

Posted by: Nacho at November 11, 2003 04:38 PM

Can you send me the code above including the projects file? I've installed Visual Studio C++, but I can't run the code. What project have I to create in Visual Studio? What files else have to be in the project?

Posted by: Gawain at November 13, 2003 03:11 PM

How can I tell MS Visual Studio, that there are other library files an other directory. I've tried with "Register PSDK Files with Visual Studio" but it didn't worked

Posted by: Gawain at November 13, 2003 03:35 PM

Gawain,

Visual Studio include and lib directories (assuming version 6) can be set from Tools/Options/Directories

I'll see if I have the project laying around and if so will post it on Sunday.

Len

Posted by: Len at November 13, 2003 04:59 PM

I have the winsock working fine on a command line win32 app. As soon as I do a CreateWindow... connect stopp working... not much of an API, usually these things work... I don't get it why they even published the whole thing on the SDK, where you can find a great sample by the way.

Posted by: Emidio at November 15, 2003 02:15 PM

Len your example works now fin. But what have I to do to built the SDK Bluetooth sample? When adding the bthcxn.cpp file to a Win32 console project, i can't compile it (Error are unresolved symbols). How to use the nmake command or integrate the bthcxn.cpp file in a project?

Posted by: Gawain at November 22, 2003 11:40 AM

I've no idea, I've not bothered with it.

Posted by: Len at November 22, 2003 11:46 AM

Hi!
I would like to know what Bluetooth devices are compatible with Microsoft Bluetooth API other than Sony Vaio. Can anybody out there who has got his Bluetooth device working with the sample program given in this site post what Blueooth hardware u r using?
Thanks in advance!

Posted by: annbc at November 27, 2003 03:08 AM

Works fine with the TDK usb adapter and the optional extra drivers from TDK. See the comments on the other bluetooth post for details.

Posted by: Len at November 27, 2003 08:33 AM

There are WHQL drivers for TDK adapters as Len pointed out - if ya need them I have em. I've compiled blue.cpp and other snippets all run fine - tho having said that my only other BT device is a 3650 and well darn I ain't gotten round to play with symbian s60 - one has a thesis to write ;) Having said that and seen whats been posted on the winsock bt stuff - I've a Q... what's wrong with opening a virtual comm port (provided by widcomm's drivers) and pulling and pushing your data that way? Look at the bemused source code.

Andy

Posted by: Andy at November 29, 2003 02:39 AM

Andy

There's nothing wrong with opening a virtual comm port if that's what you need. Personally I'm not interested in that (it's easy ;) ). I like the fact that via the Winsock stuff you can advertise your own profiles etc... That's if I ever get any time to work on it - the original client that showed an interest seems to have lost interest...

Posted by: Len at November 29, 2003 11:08 AM

Finally! Solution for native support for TDK USB dongle. Sorts out the problem of Failed to get Bluetooth socket errors. Ok here's what you do.

1. Install the TDK drivers provided with the TDK CD(currently v.1.3.2.19). Reboot. Insert TDK dongle and it will be configured.

2. Then go to ‘/Bluetooth software/Microsoft’ directory of your TDK CD-ROM and Double-click Microsoft Windows XP SP1 Bluetooth Support.exe and extract the files to the default folder. Double click Setup.exe from the folder that has just been created (C:\MSBT) and follow the on-screen instructions.

3. This will update the firmware of your dongle enabling WINXP native Bluetooth support!! Windows will then prompt again to configure the drivers. Reboot and it's all done!

Hope that helps!
Paul

Posted by: Paul at December 3, 2003 05:55 PM

Paul - do be aware that there are no services except for SDP that are advertised by the MS BT Stack :( Or at least thats what the Symbian example app BTDiscover tells me. Having said that the fact there's SDP is well cool :)

Andy

Posted by: Andy at December 4, 2003 02:25 AM

I'm desperately looking for Q323183_WXP_SP2_x86_Enu.exe If anyone can help. Thanks in advance

Posted by: Guillaume at January 3, 2004 07:09 PM

Is Q323183_WXP_SP2_x86_Enu.exe required inorder to program Bluetooth devices using winsock api? Is there any way of getting this other than from the device manufactures that have support for native Microsoft Windows Bluetooth stack.

Posted by: at January 7, 2004 01:18 AM

Is Q323183_WXP_SP2_x86_Enu.exe required inorder to program Bluetooth devices using winsock api? Is there any way of getting this other than from the device manufactures that have support for native Microsoft Windows Bluetooth stack.

Thanks.

Posted by: Uma at January 7, 2004 01:19 AM

TDK systems has got two Bluetooth USB products, Bluetooth USB Adaptor+ (Code:TRBLU03-00200-02) and Bluetooth USB Adaptor (TRBLU03-00100-00).

Bluetooth USB Adaptor+ is listed in the Windows Catalog for Bluetooth devices. Does this mean this adoptor does not require an explicit upgrade cd for Windows native Bluetooth support from TDK systems?

Which of these adopters can be used for programming using winsock api for Bluetooth?

Thanks in advance

Posted by: Uma at January 7, 2004 01:29 AM

Uma, No idea, why not ask TDK?

Posted by: Len at January 7, 2004 08:43 AM

I have sent a mail to TDK systems and haven't got any response.

I just want to know which device (USB Adopter or USB Adopter+) that some of the folks in this forum bought and got it working with an upgrade cd?

Thanks

Posted by: Uma at January 7, 2004 08:12 PM

I have the original adapter, not the + and it required the upgrade.

Posted by: Len at January 7, 2004 08:17 PM

Hello!

I have one problem with bluetooth and i hope you want help me.

I wolud like to make a program with visual c++, and i would like to use a DLL or a library that implements the functions to know the BD address and so on.Anyone knows which dll or library must i use, and if anyone knows how where i can download it, tell me.

Thanks

Barcelona,Spain

Jordi


Posted by: Jordi at January 8, 2004 06:22 PM

Hi!
Uma I have talked with TDK and they said me that both devices can be programmed with winsock api. Also, both can be used with Microsoft Bluetooth drivers. I didn´t probe it yet, it´s only that they said me.

Posted by: Nacho at January 12, 2004 09:39 AM

Hi!

What is the purpose of the SOCKET s you have? Because I have an error at the getsockopt() (error 10042).
Thanks for your help

Posted by: Marco at January 15, 2004 05:25 PM

dear Nacho,

i read your comment on a sample code of bluetooth sockets programme and you said that you got error 10108 and 10050 before. I face this error code now. Could you tell me how you could fix it?

Vivian

Posted by: Vivian at January 25, 2004 06:40 PM

Where do I obtain the MS Bluetooth QFE Stack? Or, where do I find it? Thanks a BILLION in advanced.

Posted by: David at January 26, 2004 09:59 AM

Where do I obtain the MS Bluetooth QFE Stack? Or, where do I find it? Thanks a BILLION in advanced.

Posted by: David at January 26, 2004 09:59 AM

Very interesting page. With regards to the hardware incompatibilities: Has anyone tried hacking the MS inf file for the BTHPORT driver?

All properly qualified USB Bluetooth devices conform to the same interface and can be accessed by a single driver. That should mean that modifying the inf file for the MS driver to include the IDs of, for example, the TDK should make the devices work with the MS stack. This theory should hold - especially taking in to consideration that the CSR chip (at the heart of almost all BT dongles) implements the USB I/F itself.

Unfortunately, I don't have a USB Dongle that I can experiment with and as far as I can see the BTHPORT.SYS driver isn't included with XP SP1 - it must come included with the 'officially' supported hardware (on a CD, for example)?

Cheers,
Ant.

Posted by: Antony C. Roberts at January 26, 2004 01:26 PM

LEN,

thanks for your code but it gives an error message with code 10108 after WSALookupServiceBegin. Did you have this problem before when you use your TDK Dongle?

Vivian

Posted by: Vivian at January 26, 2004 05:36 PM

If you dont have any bluetooth devices paired and there are no devices in range then you get that result from the service lookup. If you have a paired device or there's a device in range then the query will work. I assume this is normal and by design...

Posted by: Len at January 26, 2004 05:52 PM

My TDK CD only has a "Manual" folder under Bluetooth software. I don't see any "Microsoft" folder and cannot find any "Microsoft Windows XP SP1 Bluetooth Support.exe" ... I see the setup.exe, but not the Bluetooth support one. Can somebody send it to me please?

Posted by: praefectus at January 27, 2004 04:10 PM

LEN,

Thanks for your reponse.
I have a device in range which i am quite sure since i can find the device using the bluetooth manager. Would there be another other reason for having error 10108?

Vivian

Posted by: Vivian at January 27, 2004 05:07 PM

I also am having great problems detecting a Bluetooth device (an IPAQ Pocket PC) using WSALookupServiceBegin, in fact I have used the example provided by MS Platform SDK (bthcxn.cpp). I likewise get a zero handle returned and an error code 10108 (WSASERVICE_NOT_FOUND). The software is running on my desktop PC with a Belkin F8T001 USB/Blootooth adapter. I can link my desktop PC to my IPAQ Pocket PC using ActiveSync and can see the Pocket PC in "My Bluetooth Places" explorer.

Posted by: Kevin at January 28, 2004 06:24 PM

To use any of the winsock bluetooth functions you MUST have the XP SP1 bluetooth stack installed and NOT be using any third party stack to access your bluetooth hardware...

Do you have bluetooth options in the 'wireless link' control panel applet? If not then the winsock stuff WILL NOT WORK.

Posted by: Len at January 28, 2004 06:43 PM

No, I only have a "Bluetooth Configuration" applet in my Control Panel. I am also running Windows 2000 on my desktop PC. The Belkin adapter is supposed to run on Win 98/Me/2k/XP, are you saying that the winsock approach will only work under Windows XP?
What chance do I have of using the winsock approach under Windows CE / Mobile 2003 in my IPAQ Pocket PC? [I have the eMbedded Visual C++ compiler] Do you think Widecom who write the software for both Belkin and the Pocket PC would help?

Posted by: Kevin at January 28, 2004 08:43 PM

As far as I know the winsock stuff only works with the Windows XP SP1 bluetooth stack.

You may be able to get hold of the Widecom SDK and use that...

Posted by: Len at January 28, 2004 09:08 PM

Hello,

Has anyone else had any errors reporting unresolved symbol OBEXFileTransferServiceClass_UUID when linking?

Right-clicking and selecting go to definition works perfectly well and opens bthdef.h no problem. Never having used GUID's before I'm not sure if I'm mising something simple, but uuid.lib is already included.

I get this problem when trying to build my own code written from scratch and also when building Len's own example BT project.

Thanks for any help you can shed on the matter.

Sharon

Posted by: Sharrie at January 30, 2004 03:21 PM

Sharon,

Just a guess but...Is your lib path set to the latest platform SDK libs ? you may be picking up the lib that comes with the compiler and it may not be a late enough version.

Posted by: Len at January 30, 2004 03:36 PM

I have just had confirmed from Microsoft Technical Support that the Winsock approach to Bluetooth communications will not work in the IPAQ Pocket PC because it contains a Widecom stack rather than a Microsoft implementation. Widecom do provide a SDK but it is expensive (1,395 USD). I know this might be slightly off-subject, but my IPAQ 2210 has two comports, COM5 and COM8, which are supposed to transmit/receive via Bluetooth. Does anyone have any experience in programming these?
Many thanks for everyone's previous helpful comments.

Posted by: Kevin at January 30, 2004 04:33 PM

The file Q323183_WXP_SP2_X86_ENU.EXE can be found here : http://www.dvdarchiver.fr.st/Q323183_WXP_SP2_X86_ENU.EXE

Does somebody know where I can download the French version of this file ?

Posted by: LuluTchab at February 2, 2004 02:48 PM

Is this the Bluetooth stack from MS -- at this link?

Posted by: praefectus at February 3, 2004 05:17 PM

Hi,

I purchased TDK Bluetooth USB adopter. The CD that comes with it has v.1.3.2.19 and also ‘/Bluetooth software/Microsoft/Microsoft Windows XP SP1 Bluetooth Support.exe' file. If I install TDK software v1.3.2.19, attach the device, TDK drivers are installed. If I try to update the drivers for the device through Device Manager to use the drivers in c:\MSBT ( where the Bluetooth SUpport for Microsoft stack are extracted), then the Add Hardware Wizard complains that it could not find the better software than the current one.
I had to uninstall TDK software(v1.3.2.19) inorder to be able use the Microsoft Bluetooth stack. I could see the wireless link and the Bluetooth tab in it? I could discover other devices.

One gentle man, Paul, pointed in this message that "Setup.exe" in C:\MSBT need to clicked inorder to update the firmware. I did not see any setup.exe executable in the c:\MSBT.

I am wondering whether my setup is fine. I didn't purchase any upgrade cd as many people were talking about.

When I ran the program given in this web page on my first pc, my other pc (witrh D-Link BT USB device)is able to discover the service. But when I try to send a file from the other pc, it complains that it could not establish the connection. My program is waiting at the accept() call and it is not seeing any incoming connection.

Can somebody figure out what is going wrong?

Posted by: Uma at February 4, 2004 01:57 AM

To install the MS stack you need to uninstall the TDK drivers.

I expect the dongle you bought already has the latest firmware; mine needed an upgrade to work with the MS stack, I think the installation of the stack spotted this and did it for me, cant remember.

No idea re your problem with the code. I know this doesn't help but, "it works for me".

Posted by: Len at February 4, 2004 09:31 AM

Installed from the above link, but it didn't do anything -- which device was this for? (from the link http://www.dvdarchiver.fr.st/Q323183_WXP_SP2_X86_ENU.EXE)

Posted by: praefectus at February 4, 2004 03:41 PM

Not sure if I should post this here, but here goes...

Reply to Kevin's iPaq question:

I've been "playing" with BT on an iPaq5450 for a while now as the 3rd part in an embedded BT application using HCI-UART.

The iPaq is annoying. From what I've found: there is a serial port in the iPaq to which the BT module is connected (I can't remember the number now). I found the port using some WindowsCE Registry editing software called "Kilmist Regedit" (Let's say that there have been some, eh, iPaq "problems" in the meanwhile...)

I can open the port if I do not activate the BT.
I can not open the port if the BT is activated (Widcomm).
I can not activate the (Widcomm) BT if I have the port open.

To me this seems to indicate that that port could be used to send and receive HCI traffic. In my case though, I do not know how to turn _ON_ the actual BT hardware without activating all the Widcomm stuff.

I know this is a "half answer" but I am stuck on this point with the iPaq.

Posted by: Jeroen at February 5, 2004 06:05 AM

thanks a lot for your program.

i have a problem when using connect(SOCKET s, const sockaddr * name, int namelen) from winsock. when i use SOCKADDR_BTH on sockaddr compiler says can convert.

i also have some problem about how to fill :
address.serviceClassId = __nogc new System::Guid(OBEXObjectPushServiceClass_UUID)

the compiler says "error C2664: 'System::Guid::Guid(unsigned char __gc[])' : cannot convert parameter 1 from 'const GUID' to 'unsigned char __gc[]'"

i have no idea...

please help me.. thx.

have some bluetooth send file with visual c application ??

thanks alot..

Posted by: xins at February 5, 2004 08:18 AM

Hi,

Example code is great, thanks for having it here.

Unfortunately I won't be able to use it directly as we need to develop for a more generic platform than just XP-supported BT adaptors - we need to support anything that works as a virtual serial port.

Could you briefly recommend what areas of this code I could use, and what I'd need to change, to use sockets via a BT adaptor's virtual comm port drivers? Or would it involve a whole different approach?

Cheers

Posted by: Philip McDermott at February 5, 2004 09:25 AM

Philip

I've no idea, sorry. We've only been looking at supporting Windows XP BT adatpters for clients and only via the winsock interface.

Len

Posted by: Len at February 5, 2004 09:53 AM

Xins

Looks like you're converting the code to managed C++? I dont have time to debug the errors for you, sorry.

Len

Posted by: Len at February 5, 2004 09:54 AM

Thanks anyway.

Can I just check with you, as I'm not in a position at the moment where I can run the code: do your two calls to WSALookupServiceBegin() do different things: i.e. first time device discovery, and second time service discovery?

Posted by: Philip McDermott at February 5, 2004 03:05 PM

Philip,

Yes, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bluetooth/bluetooth/bluetooth_and_wsalookupservicebegin_for_service_discovery.asp for details.

Posted by: Len at February 5, 2004 03:44 PM

Can anybody answer the questions about in regards to WHERE to get this MS Bluetooth stack?

Posted by: William at February 11, 2004 11:01 AM

You get it from your device manufacturer.

Posted by: Len at February 11, 2004 02:22 PM

That's true, but not all device manufacturers make this available .... also, there is a link to a Bluetooth stack above, but my previous question was WHAT device was this BT stack for? Does anybody have a TDK version of MS BT Stack? My CD didn't come with it...

Posted by: at February 12, 2004 12:32 PM

Newer TDK dongles come with the XP stack on the cd, older ones didnt. If you dont have the stack you can purchase it from TDK from here:

http://www.tdkshop.com/products.aspx?catid=5

Posted by: Len at February 12, 2004 12:53 PM

Hi,
I'm developing an accademic project working with Pocket PC and notebooks. I want to realize a simple comunication between this two kinds of devices using bluetooth technology. Which is the easiest way to make this? Searching with Google I've found this article, that describe the use of serial port: http://www.devx.com/wireless/Article/11511 but doesn't work. Can someone help me? I have tried to develop similar programs for desktops and I can transfer text between devices but I can't understand because on Pocket PC a similar program doesn't work. PS On both Pocket PC and Desktop is installed Widcomm stack.

Thanks of all
Marco

Posted by: Marco at February 14, 2004 10:27 AM

I bought a Kensington USB Bluetooth adapter. What is odd is that it is not even listed as a product on their website. It came with a CD with WIDCOMM software on it, but when I installed that, the process went thorugh and could not install the driver for my device ("Correct INF section not found" or something). I downloaded the 323183 update from this site and installed it. When i put in the dongle after this, the computer recognized it and installed the Microsoft drivers ("Microsoft Bluetooth Enumerator" and "USB Bluetooth Device"). I can use the computer to display and connect to an iPAQ 4150, but no functionality is implemented (other than a "Dial-up Networking Service" for which I cannot fathom a purpose or make use of). My real goal is to use ActiveSync via Bluetooth, but this requires a COM port to be mapped to the adapter, which the current setup does not appear to allow. Reinstalling WIDCOMM after the MS Bluetooth installation brought no change. Does anybody know how to bridge my Bluetooth to a COM port? Perhaps there is some updated WIDCOMM library or an add-on for the Microsoft API? Thank you.

Posted by: Matt Lucas at February 17, 2004 04:28 AM

Download MS Bluetooth stack from microsoft (signitured driver and QFE):

http://www.microsoft.com/whdc/hwtest/search/details.aspx?ID=660

Posted by: Lobkov at February 19, 2004 08:00 PM

To see the list of 'designed for Windows XP' Bluetooth hardware, see:
http://www.microsoft.com/windows/catalog/default.aspx?subID=21&xslt=search&qu=bluetooth+&scope=1&btnSearch=Go

I have compiled the code sample above using MS VC++.
It opens socket# 1912. But when it calls the WSALookupServiceBegin(&querySet, flags, &hLookup) if fails with error code 10108. The error code is not in the Platform SDK help ( ms-help://MS.PSDK.1033/winsock/winsock/windows_sockets_error_codes_2.htm )

As someone asked earlier, is this because of the HW?

My system is:
SW: Windows XP Pro SP1, Platform SDK and Q323183_WXP_SP2_X86_ENU.EXE installed. (Widcomm BT stack).
HW: CSR USB Bluetooth Device.

Hansson

Posted by: hansson at March 3, 2004 04:04 PM

Hi Len,

I use your code for Service-Detection and can find the OBEX FileTransfer-Service. Now I want use this service for copy files from PC to Pocket PC (IPAQ2210). How does that function?

Posted by: Mike at March 10, 2004 08:15 AM

Mike,

Search this site for OBEX and then follow the links to the OBEX spec. It explains how the file transfer stuff works. The precompiled example server I have here dummies out the server side of an OBEX file transfer system, it may be helpful for you to use it to dump the packets that a client sends to the server whilst you're looking at the spec.

Posted by: Len at March 10, 2004 09:17 AM

Hi Len and bluetooth gurus,
I have installed the sp1 patch. I am not able to get past the socket function, might be the hardware!!
The sp1 patch claims to put these drivers among many - bthenum.sys, bthport.sys, rfcomm.sys. I believe these are the bluetooth stack drivers. Any of you whose program is working - Do you have these drivers loaded in the system(entry in HKLM\sytem). I have these sys files but they are not registered and loaded i.e, not in the registry. Since the drivers are not loaded, the winsock layer does not recognize bt protocol.
If you can let me know the status of these drivers --
Thanks in advance to you all
jahangir

Posted by: jahangir at March 10, 2004 10:21 AM

Hey guys, not sure if anyone is still checking this list, but I just bought the Sony VAIO USB BT adapter which uses the MS drivers for my laptop. The code works fine with it obviously. I also have the Belkin adapter on my PC. The Sony adapter works with the code and all, but the MS drivers aren't very useful compared to the WIDCOMM drivers for the non-MS adapters. I wish MSFT would get off their ass. On the bright side, I also bought the MS Bluetooth mouse which is real nice.

Posted by: sfiorito at March 19, 2004 03:56 AM

With the support provided by the XP Sp1 stack we dont need MS to get off their ass... We can write our own services...

Posted by: Len at March 19, 2004 07:44 AM

I've got CSR Usb dongle and it works alright with the stack in the supplementary pack. Thanks for the code!

Posted by: pago at March 19, 2004 04:07 PM

sfiorito,
could you tell me which model of laptop are you using?

I used ANYCOM USB Adapter in my laptop and it could run the above code sucessfully but when i used it in my desktop with the same OS (XP sp1), it returns error "Failed to get bluetooth socket! An address incompatible with the requested protocol was used"...

Posted by: Vivian at March 19, 2004 04:49 PM

It's an AOPEN (from ABS) barebones laptop. Sony says their adaptor only works with VAIO computers, but that's not true.

Posted by: sfiorito at March 22, 2004 11:36 PM

hi!
Len, have you probed this code with the new TDK drivers that you said you downloaded? it works? Thanks

Posted by: Nacho at March 24, 2004 12:40 PM

I purchased a disk of drivers from TDK and yes, it works with that disk.

Posted by: Len Holgate at March 24, 2004 02:28 PM

from where can I downoad the platform sdk which contaon the Ws2bth.h file and the others ?
I have win XP
thanks
Zachi

Posted by: zachi at March 24, 2004 07:51 PM

Google is your friend...

http://www.google.com/search?sourceid=navclient&q=platform+sdk

Posted by: Len at March 24, 2004 08:00 PM

which one of the SDK I have to download ?

Posted by: zachi at March 24, 2004 09:45 PM

I saw that each of the .cab file I have to download from http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm
i sabout 25MB (quite heavy)
do u have only the h files I need in order to run your application or is it necessury to have all the k on my PC

Posted by: zachi at March 24, 2004 10:50 PM

Hi Len!
These are my two last questions (I hope): your TDK device is class 1 or class 2? and the disk of drivers you purchased from TDK is Microsoft Bluetooth stack CD or USB & PC Card Software CD? Thank you very much. Regards

Posted by: Nacho at March 29, 2004 09:40 AM

Hi EveryBody!

You're right. It's necessary that Win XP recognize your Bluetooth device natively. That's because the RFCOMM protocol we are using to open virtual serial ports. RFCOMM protocol interact directly with the Port Emulation Entity (Socket).
Win XP SP1 gives a correct way to communicate those elements, but if you need to install new drivers, those elements will not comunicate properly and that's why we encountered the SOCKET's different errors.

Well, is not exacly like this but you can have an idea.

Posted by: Javi at May 20, 2004 11:58 AM

Hi

I have the exact same problem as Deepak above. The program initialises everything just fine but then hangs on accept.

I try to connect from my Sony Ericsson phone and I find the computer but it is not possible to connect. The phone asks for the PIN code and the there´s just a message stating that I can´t connect. I can also not browse the registered OBEX service.

I have tried both with the Microsoft and the TDK dongle. Both of them works fine and I have another application running on the MS API, however I just can get the server and service functionality to work.

All comments appriciated.

Posted by: hubbobubbo at May 25, 2004 01:33 PM

Hi!

I have a problem with the WSALookupServiceBegin function to discover the bluetooth devices. I get 10022 Error when i execute the WSALookupServiceBegin function.

Here is the code i'm using.
This code is the code that i use in my Pocket Pc (not in a Pc). I want to comunicate my Pocket Pc with my Pc via Bluetooth with sockets:

WSADATA data;

if(WSAStartup(0x202,&data)==0)
{
//Se ha iniciado correctamente la libreria ws2.dll//

WSAQUERYSET Query1;
LPHANDLE Handle1=NULL;

Query1.dwSize=sizeof(WSAQUERYSET);
Query1.dwNameSpace=NS_BTH;

if(WSALookupServiceBegin(&Query1,LUP_RETURN_NAME|LUP_RETURN_ADDR,Handle1)==0)
{
//Se ha iniciado correctamente la busqueda de dispositivos//
DWORD ret;
LPDWORD tam;

do
{
tam=(unsigned long *)sizeof(Query1);
ret=WSALookupServiceNext(Handle1,NULL,tam,&Query1);
MessageBox((CString)Query1.lpszServiceInstanceName);

}while(ret!=WSA_E_NO_MORE);

}
else
{
//Error en la inicialización de la busqueda de dispositivos//
CString a;
a.Format(_T("Error en la inicialización de la búqueda de dispositivos. Error %d"),GetLastError());
MessageBox(a,(CString)"WSALookupServiceBegin Error",MB_OK|MB_ICONERROR);
}
}
else
{
//No se ha podido iniciar la libreria ws2.dll//

MessageBox((CString)"No se ha podido iniciar la libreria ws2.dll",(CString)"WS2.dll no Iniciada",MB_OK|MB_ICONERROR);
}

WSACleanup();

//////////////////////////////

Anyone knows where is or can be the problem?

Thanks in advance!

Posted by: Synth2 at May 28, 2004 09:46 AM

I've no idea if the Winsock stuff works the same way on non Windows XP platforms...

Posted by: Len Holgate at May 28, 2004 11:23 AM

Thanks anyway!

Posted by: Synth2 at May 28, 2004 12:11 PM

Has no one had any problems with socket accept as in my question above. I´m getting realy confused here since all works well otherwise.

Posted by: hubbobubbo at June 1, 2004 03:24 PM

Does it work if you pair the devices first so that the pin prompt doesn't happen?

Posted by: Len Holgate at June 1, 2004 05:24 PM

Hi,
I am having a problem in that, I get an unresolved symbol for _L2CAP_PROTOCOL_UUID. I was used uuid.lib and all *guid.lib file also.

#pragma comment(lib,"uuid.lib")

But i'm getting the same error always. How can i rectify this problem?

I'm using 3Com USB Bluetooth Dongle., and Microsoft XP Sp1 Bluetooth Stack(Driver file).

Thanks in advance.

Posted by: at June 2, 2004 08:30 AM

See my response to Sharon above; make sure you're picking up the platform SDK libraries.

Posted by: Len at June 2, 2004 08:39 AM

Hello!

People tell me that, with bluetooth, we can only have 8 connections per device.
I'm developing a project where many Pocket Pc's (20 more or less) needs to connect to a Server (PC Windows XP) via Bluetooth.
I thought that with WinSock i will be able to connect this 20 Pocket Pc's to the server (not simultaniusly), but if only can connect 8 devices, how can i make this possible?

Any other way to make this without using WinSockets?

Thanks in advance and sorry for my messages

Posted by: Synth2 at June 2, 2004 10:30 AM

Hi Len,
Thanks for your qucik response. I'm using the latest SDK(Microsoft Platform SDK Feb 2003). And i have given the link also.

Which SDK i was installed is it ok., Or do i need to update any other SDK also?

I have some other doubts., how can we set the device as Test Mode. In default its setting in Normal Mode. Do we have any WinApi to set as Test Mode?

Once again Thanks for your help.

Posted by: at June 3, 2004 01:53 AM

Hi,

I wrote a program to access my mobiles (Nokia3650, SonyEricssonP800) over BTH WinXP Bluetooth sockets. I wrote a little Symbian OS server with Metrowerks c++ and it works very well over WinXP BTH. Now I try to have the same access if there are (only) Widcomm drivers on the PC. I don't have the mony for the Widcomm SDK(s). Is there a way to get a connection over Win sockets with Widcomm???

Christine

Posted by: Christian Ohle at July 3, 2004 05:17 PM

How i can download ws2bth.h
bluetoothapis.h?
thank you?

Posted by: thabti at July 9, 2004 08:26 AM

Len,

I tried your code on service discovery and it worked for me. Do you know how I can connect to another bluetooth device using winsock? Actually I want to connect to a specific bluetooth device.

Thanks,

Hans

Posted by: Hans at July 21, 2004 05:21 PM

Hans

I haven't actually done any outbound connections...

Len

Posted by: Len Holgate at July 21, 2004 05:40 PM

Could someone please share with me the Microsoft Bluetooth Stack for the TDK USB Dongle. I need it badly. The one that I have doesnt have a Setup.exe file in it.

Thanks

Ahtasham
ahtasham_a@hotmail.com

Posted by: Ahtasham at July 22, 2004 06:04 PM

You can buy it from TDK, there's a link to their shop in one of the comments on one of the bluetooth articles here.

Posted by: Len Holgate at July 22, 2004 06:07 PM

I have bought a acer aspire 2010 it had windows xp home on it so I updated to xp prof, now th ebluetooth does not work, it can not find the device at all. All the software is installed and it still fails. I re imaged back to xp home and again it fails to find any blue tooth device.
It is widcom device built in, does anyone kno whow to bring it back the device?

Posted by: smiler at July 22, 2004 07:41 PM

Len, When I get the things working using the MS TDK stack, will it allow me to do the serial data transfer using the COM port?

Thanks, Ahtasham

Posted by: Ahtasham at July 22, 2004 10:20 PM

Ahtasham

I'm not sure that you can, the MS stack have very limited support for services at present. It only seems to support 'dial up networking' and, of course, all the programatic stuff that you can get to via Winsock. I guess it may depend on the device you're trying to connect to, but...

Len

Posted by: Len at July 23, 2004 07:52 AM

Len, What would be the possible protocol/profile selection using the MS TDK stack if one has to do a simple data transfer from one TDK bluetooth module to the other.

Thanks, Ahtasham

Posted by: Ahtasham Ashraf at July 27, 2004 05:37 PM

Ahtasham,

I've no idea; if you can write the code at both ends of the connection then I'd just open a socket connection using something like OBEXFileTransferServiceClass_UUID and squirt bytes back and forth...

Posted by: Len at July 29, 2004 12:13 AM

Hi,
I have installed Windows SP2 pack and i have written a VC++ application over using bluetooth apis and Winsock . But when i compile i get an error :
uuid.lib(bthguid.obj) : fatal error LNK1103: debugging information corrupt; recompile module.

I have the proper directories path set.

please can anyone help....

-Sid

Posted by: Sidharth at July 29, 2004 10:24 AM

I get the same error as Sidhart above with the new SP2 for XP. Anyone know the solution. I have posted an error report to MS but I guess a response is unlikely.

Posted by: hubbobubbo at August 12, 2004 08:10 PM

Has anybody had the issue that bluetooth devices are cached even when LUP_FLUSHCACHE is set?

Posted by: Simon Smithdom at August 18, 2004 04:03 PM

Try using the uuid.lib that comes with the latest platform sdk?

Posted by: Len Holgate at August 18, 2004 05:31 PM

Hello everybody. I know is not a good question for this web, but anybody knows how can i register a control in a Pocket Pc using embedded Visual C++ language?
in my programm im using a special control and i need to register it when i install the application into the Pocket Pc. Anyone knows the code needed to do it??

thanks in advance!

Posted by: Synth2 at September 7, 2004 03:53 PM

i would like to know the api for bluetooth in visual C++,as i am planning to design a wireless application between pc to pc .

Posted by: ritesh at September 12, 2004 08:56 AM

please sent me the sample code for bluetooth api

Posted by: ritesh at September 12, 2004 08:58 AM

Ritesh

It's here, in this posting, that's all there is.

Posted by: Len at September 12, 2004 10:08 AM


I got a linking error in visual studio 6 pro.

LINK : fatal error LNK1104: cannot open file "C:Program FilesMicrosoft SDKLibws2_32.lib"

please help.

Posted by: Vladimir Vincent at September 23, 2004 11:55 PM

Hi Ronald,
My mail is with the reference to the article published in the link http://www.lenholgate.com/archives/000102.html, and your comment there. You are the first person except Len who said the code is running and you could send message over bluetooth devices. I have tried several times with the same code and the code does not compile directly!!! First it gives compilation error "_L2CAP_PROTOCOL_UUID", after some copy and paste, the code cannot open socket!!! If the socket openning code is blocked, the Service Begin is giving error!!! This is the only example of Bluetooth in Windows over the net I could found and that also does not work! I am really getting frustrated. So I need your help in this regard, please don't say know!!!
1. What is the OS, Service Pack, SDK version, compiler version you have used to compile the code?
2. Does the code depend upon the Bluetooth driver provider? I am using Widcom's drivers.
3. Is it possible that I have the project workspace including the dsp, dsw, cpp or whatever, which you could compile and could run?
Eagerly waiting for help.
Thanks!
Kausik

Posted by: Kausik at September 24, 2004 01:23 PM

Hi Ronald and Len,
My mail is with the reference to the article published in the link http://www.lenholgate.com/archives/000102.html, and your comment there. I have tried several times with the same code and the code does not compile directly!!! First it gives compilation error "_L2CAP_PROTOCOL_UUID", after some copy and paste, the code cannot open socket!!! If the socket openning code is blocked, the Service Begin is giving error (err no: 10108)!!! This is the only example of Bluetooth in Windows over the net I could find and that also does not work for me? I am really getting frustrated. So I need your help in this regard, please don't say no!!!
1. What is the OS, Service Pack, SDK version, compiler version you have used to compile the code?
2. Does the code depend upon the Bluetooth driver provider? I am using Widcom's drivers.
3. Is it possible that I have the project workspace including the dsp, dsw, cpp or whatever, which you could compile and could run?
Eagerly waiting for help.
Thanks!
Kausik

Posted by: Kausik at September 24, 2004 01:25 PM

Kausic,
The code does compile without changes. As mentioned in other comments you need XP SP1 and bluetooth hardware that has native support (read the other comments if you don't know what that means). You need the latest Platform SDK installed (properly).

To check your hardware you could download the Bluetooth server exe from this site, if that runs OK then your hardware will work with this code.

Posted by: Len at September 24, 2004 05:39 PM

Hello,

In your code, you use two files which are:

Header: BluetoothAPIs.h.
Library: Irprops.lib.

I have Windows XP SP2 and I searched my machine for these files but I didn' find them. From where can I get these files?

Best Regards,
Belal


Posted by: Belal Marzouk at October 7, 2004 12:09 PM

Platform SDK

Posted by: Len at October 7, 2004 12:33 PM

Hi Len,

May be this is a bit off topic. I need to know from where I can get the following DLLs:

* BthUtil.dll
* ws2.dll
* Btdrt.dll
* coredll.dll

Thanks :-)

Manu

Posted by: Manu at October 16, 2004 06:55 PM

Platform SDK

Posted by: Len at October 17, 2004 09:14 AM

Simon Smithdom: yes, i have the same issue. im not running exacltly this code though. i modified the bthcxn.cpp found in the platform sdk under samples/netds/bluetooth. this because i could not get the code above to work because of the L2CAP_PROTOCOL_UUID.

Posted by: Micael Sjölund at October 18, 2004 10:05 AM

Just noticed that if a device is bonded and added to the device list in windows xp bluetooth, then it will always be cached when running the WSAService methods. if i remove the device from the bonded list, then the code will only find the device if it is discoverable.

Posted by: Micael Sjölund at October 18, 2004 10:29 AM

hi~

My phone(Samsung phone) has 5 bluetooth services
(Headset, Handsfree, ObexFileTransfer, Network Dial Up, Serial Port service)

When I try to communicate pc with phone
using Bluetooth APIs, I could make only serial port service enable.

this code works well)
pGuidService = (GUID)SerialPortServiceClass_UUID;
dwErr = BluetoothSetServiceState(NULL, &deviceInfo, &pGuidService, BLUETOOTH_SERVICE_ENABLE);

but, this code don't work)
pGuidService = (GUID)DialupNetworkingServiceClass_UUID;
dwErr = BluetoothSetServiceState(NULL, &deviceInfo, &pGuidService, BLUETOOTH_SERVICE_ENABLE);

dwErr code is ERROR_SERVICE_DOES_NOT_EXIST (Why??)

1. How can I make other services enable?
2. Doesn't MS Bluetooth Driver support other services except SerialPort Service?

MS Bluetooth common dlg also finds only SerialPort Service.

Using socket, I can find services MyPhone has.
3. Is it possible to enable other services using Socket?


I can't speak english well.. sorry ^^

Posted by: jack at October 25, 2004 10:44 PM

The simple answer is, I don't know. I also don't really have time to investigate this right now. Perhaps one of the other readers can help.

Posted by: Len Holgate at October 26, 2004 10:29 AM

In order to get the GUIDs working (i.e. your linker cannot resolve an address for L2CAP_PROTOCOL_UUID for example) you need to add in this define...


#define INITGUID

This will make your compiler actually initialise the GUIDs (which are simple structs) rather than just put their prototypes into the code and say that they are an 'extern far' struct.


Hope this helps some guys/gals....

Posted by: si at October 27, 2004 03:29 PM

hi len,great stuff u got here.sorry to disturb u with a simple problem. plz plz,help me with this as it is very important for my project.
in my project ,i want to use bluetooth enabled phone using a serial port.i have a CSR bluetooth dongle with widcomm bluetooth stack.
i am using the serial port for writing data .the createfile handle is not getting created or if it is created ,the writefile writes zero bytes to the virtual comm port 3(i.e that is what system initializes).
can u send me some sample code .or can u pinpoint the problem.

thanks a lot i advance

regards
garry

Posted by: garry at November 15, 2004 07:10 AM

I haven't done a great deal of work using bluetooth virtual com ports. Make sure that you're passing the correct arguments to create file, I seem to remember that the args are special for com port 'files'...

Posted by: Len at November 15, 2004 07:19 AM

hi len,
i have a very simple problem that seems to be maddeningly difficult to solve.here it is:
i am trying to communicate with a bluetooth enabled nokia 6600 with the the help of a csr dongle that has widcomm drivers support.i tried to write a program to send gps data over virtual comm port to the mobile phone.so i wrote a simple program using normal api's.however the program gets stuck at the "createfile" step.simultaneously,a windows comes on my mobile screen telling me that my pc is trying to connect?accept or not?on giving yes,no action takes place.will windows api not work? do i have to buy the widcomm sdk?sometimes a handle gets created but writefile operation returns with error 1226.
i must also add that i am not able to communicate through hyperterminal with comm port?does that mean normal serial port communication is not possible? plz reply back quickly as a i have deadline for this project.

Thanks in advance
with regards
garry

p.s i am using win xp with sp2 and compliant SDK and also have applied the qfe patch.

Posted by: garry at November 17, 2004 05:19 AM

Garry

I've no idea.

Posted by: Len Holgate at November 17, 2004 10:39 AM

Hi Len,
first thanks for your code, i've been struggling for 6 weeks to comeup with something that works and your code has given me a big moral boost

But i'm getting the following link error when i compile:
uuid.lib(bthguid.obj) : fatal error LNK1103: debugging information corrupt; recompile module

i've seen this problem mentionned twice by other readers but i cant see a solution.
Im using XP with service pack 2 and the SP2 SDK (MS Visual C++ 6). I've heard that it could be to do with the version of uuid.lib in the SP2 sdk, but i cant find a source for an older version of uuid.lib or an older version of the complete sdk.
Any advice that you could offer would be greatly appreciated
thanks
Jon

Posted by: Jonathan Kaye at November 21, 2004 07:02 PM

Hi again,
I've done a bit more digging around. I used your provided project zip download, and on the first attempt at building, i got:

blue.obj : error LNK2001: unresolved external symbol _OBEXFileTransferServiceClass_UUID

this error has been mentionned in a previous post and you recommended making sure that the compiler was refering to the correct version of uuid.lib.
So i moved the microsoft SDK lib path to the top of my library directories and tried another build.
This time i got the same 'debugging information currupt' error as in my last post. So i'm pretty sure that it is to do with the version of uuid.lib that i'm using.
could you upload or email the version of uuid.lib that worked for you? or do u hav any other ideas?
thanks

Posted by: Jonathan Kaye at November 21, 2004 07:28 PM

Ok, third post in a row, lol.

Well thanks Len, re-installed XP with sp1 this morning, plugged in my TDK dongle, extracted the microsoft files from the TDK cd to a folder on my HD, told windows to look there for the dongle drivers and hey presto i had a native bluetooth device, lol.
Installed SDK with the older version of uuid.lib that u sent and the code compiled perfectly.
Program worked first time and found all of my bluetooth devices. So thanks for your help, you've given me a great starting point for my project.
Regards
Jon

Posted by: Jonathan Kaye at November 22, 2004 02:12 PM

Cool. Good luck with the project.

Posted by: Len Holgate at November 22, 2004 02:57 PM

Hi Len,
I've a simple problem, but i'm a newbie developing with bluetooth devices. Am I able to get back the signal strength from the standard windows bluetooth functions? Is this possible by programming on Windows socket layer?
How can I know, if a bluetooth device is in range by standard windows functions? I always get back devices which are not in range (only in cache).
Thanks 4 your help (you already gave me with this site)
Sebastian

Posted by: Sebastian Buckpesch at December 3, 2004 01:32 PM

Hi everybody,

I write a project to connect up to seven terminals to a pc with bluetooth serial port services.
My program searches for new devices, creates a serial port service named with the discovered device's bluetooth address and paires it.
After a successful pairing, device try to connect to a serial port service on the PC named with its own address.

Now, everything works but I have a little problem. I don't know how modify the setlinksupervisiontimeout of the pc. The pc wait 20 seconds before update the connecting state of a device.
I would reduce this refresh time to 1 second. normally, it's a HCI frame which control linktimeout, so how do you use HCI frame with socket programming ?

thank you very much.

Jérôme

Posted by: MATHIEU Jérôme at December 6, 2004 09:15 AM

Hey Len, great stuff you have here. I am on a team here trying to learn about bluetooth so we can implement our 2 quarter project: a general purpose library implementing the BPP protocal (Basic Printing Profile). I need to get some startup ideas/links/code to get us going in the right direction. Looks like you have some good code up top, but our dev environment is constrained to C#.

Will I have to write a C++ dll (none of us know C++ well) and add it as a ref?

Thanks

Posted by: RIT SP Team at December 8, 2004 03:36 AM

Hey Len, great stuff you have here. I am on a team here trying to learn about bluetooth so we can implement our 2 quarter project: a general purpose library implementing the BPP protocal (Basic Printing Profile). I need to get some startup ideas/links/code to get us going in the right direction. Looks like you have some good code up top, but our dev environment is constrained to C#.

Will I have to write a C++ dll (none of us know C++ well) and add it as a ref?

Thanks

Posted by: RIT SP Team at December 8, 2004 03:36 AM

_L2CAP_PROTOCOL_UUID usually user defines it..
(int)

It's a service number, that other bluetooth devices look for when looking for connection...

through this number bluetooth devices find out which programs(services) are running on one bluetooth..

Posted by: at December 8, 2004 10:32 PM

Hi, great to have a place where you can discuss Microsoft Bluetooth.

I am using some of the above code to discover a service I have written on my mobile phone.

When I try to discover it with the above code and
GUID protocol = L2CAP_PROTOCOL_UUID; I am able to see a lot of predefined services but not the one I provide.

DEFINE_GUID(myservice,0x00001234 , 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);

Defining a GUI that matches my service class (1234) on the phone does not help.

Anyone with a good ide?
What does the rest of the numbers mean after the service class?

Posted by: Thomas at December 30, 2004 02:53 PM

Hi to everybody!
I am also writing an application to link seven bluetooth devices to the laptop and I have the following problem:
When I compile the program the following error ocurs; LNK1103 (linker error) it says that I have to recompile the uuid.lib library.
When I try Len's code the same happens, and I have discovered that this problem is ocasioned by the following code:

GUID protocol = L2CAP_PROTOCOL_UUID;

querySet2.lpServiceClassId = &protocol;

When I change the service (to serial or whatever)it happens the same.I can't erase this part of the program because it is necesary to discover the services. Anybody knows what is happening?.
Finally, anybody can tell me the diference between "BluetoothFindFirstRadio" and "BluetoothFindFirstDevice"?

Thank you

Posted by: Asier at December 30, 2004 04:48 PM

I have a problem. I am not able to list the services offered by my PC connected to the Bluetooth adapter using the code posted by Len. Can someone help please?

thanks a lot

Posted by: Rehan at January 5, 2005 09:33 PM

Thanks for providing some great examples, Len. They've been an excellent tutorial.

Do you have any examples of SDP advertising with the "blob method"? MSDN has a few for the CE implementation, but the XP libraries diverge here. Thanks!

Posted by: RIT SP Team at January 17, 2005 09:03 PM

Hallo, can anybody help me?

My first problem:
I'm able to read the count of the connected buetooth sticks with "BluetoothFindFirstDevice", fine. But has someone tried to connect more than one bluetooth adapter? I get an error in device manager (error code 10 -device failed to start) for the second bluetooth adapter!
(The first adapter works -no errors)
The two adapters are equal (acer, BT-700, class 1).
Has anybody experiences with this problem? Can I avoid this with any registry entry?

My second problem:
I have a program like the great example above. (THANKS !!!) The program read and writes over RFCOM protocol.
If I plug out and plug in the bluetooth adapter again while the programm runs (during no connection is active), the winsock command "connect" fails with error code 10022! All other instruction cause no errors.

I'm sorry, my english is not very good! I hope you understood!

Posted by: Erik at January 22, 2005 09:39 AM

Above, in the first problem, I meant not "BluetoothFindFirstDevice", but "BluetoothFindFirstRadio"

Posted by: Erik at January 22, 2005 10:39 AM

Len could you send me the copy of the Uuid.lib file you are using. I have the same problem mentioned above. early version w/vc6 does not include the definiation and then w/sp2 definition get the corrupt recompile link message. thanks a ton. so far I've got a lot to to work. I do not know if I will have to use sockets but I need to be able to enable/disable remove/add bluetooth devices for now. Your code is great though it helped me out alot. The sockets where way easier. I had the socket working before I even had the bluetooth.cpl working.

thanks again
tom

Posted by: Thomas at January 26, 2005 07:15 PM

Hi Len,

I am absolutely new to this application, in fact new to this feild as well the only exposure being a winsock server/client application partially developed last year over TCP/IP. I am interested in baming an application using MS SDK to communicate with Bluetooth slave modules connected to energy meters, the application should be able to discover these devices and one by one exchange data with them. Could you suggest which profiles from Bluetooth should i be using. Also is there a place where Bluetoothapis.h and other relevent files can be downloaded.
thanks

Posted by: Nishant at January 27, 2005 06:33 AM

Nishant I saw your comment to len and I was just going to let you know that you can just program most things over a standard emulated serial port. Your program will interact with the com port just the same as if it was wired to Com1. The probelm most have with this is you can not tell when you lose a connection you do not know that you lost a connection with out interacting with the sockets. In my application I'm trying to figure out a way to have almost a perminant wireless connection.

Posted by: Thomas at January 27, 2005 06:10 PM

can anyone help me find a direct link to the Platform SDK, plz

Posted by: sherif at January 30, 2005 05:29 PM

where can i download the Platform SDK

Posted by: sherif at January 30, 2005 05:34 PM

Hi Thomas,

Thanks for your reply, i have made some progress, in the sense that i have figured out where to get the bluetoothapis.h etc, tried to download it via the microsoft website, unfortunately some of the .cab's were corrupt, have ordered a cd for myself.(i know lotts ms haters would say move onto something else, but other stuff is expensive)..Do you have any documents which i can refer to for buliding my application, initially i am looking to build a Console applications on C which will emulate the bluetooth dongle as a serial port and discover devices and send and receive data and close connection.
Thanks again.

Posted by: Nishant at February 1, 2005 02:49 PM

Hi.
I have the same problem with writing a server application for bluetooth.

I tried the WsaSetService thing.
and after this i gave out all registered services in a loop.
but the new created on isnt there :( so i think
this is maybe the problem for the accept problem ?

maybe we should try another way of register out services for bt.

Cya

Posted by: Marcel Cevani at February 5, 2005 07:57 PM

HI,
I have been able to registter the Serial Port service in the database using WSAQuerySet, but wihtout using lpblob. Wen i tried with lpblob, im getting error 10022(WSAEINVAL)
Can anybody plz tell me wat cud be the problem.

Here is the record im using

unsigned char szSDPRecord []={0x1C, 0x00, 0x04, 0x1A,0x1C, 0x01, 0x00, 0x1C, 0x00, 0x03,0x01,0x01, 0x1D, 0x80,0x00, 0x00, 0x11, 0x01, 0x00,0x00,0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B,0x34,0xFB
};
WSAESETSERVICEOP enServiceOp=RNRSERVICE_REGISTER;
DWORD dwControlFlag = 0;
other parameters are as follows
memset (pstRegInfo, 0x00,sizeof (WSAQUERYSET));
nServiceSize = sizeof (BTH_SET_SERVICE);
nServiceSize = nServiceSize + sizeof(szSDPRecord);
nServiceSize = nServiceSize - 1;
pstService = (BTH_SET_SERVICE *)malloc (nServiceSize);

memset (pstService, 0x00, nServiceSize);

pstService->pSdpVersion = &ulSDPVersion;
//pstService->fCodService =
SET_COD_MAJOR(pstService->fCodService,COD_MAJOR_COMPUTER) ;
SET_COD_MINOR(pstService->fCodService,COD_COMPUTER_MINOR_DESKTOP) ;

pstService->pRecordHandle = &pulRecordHandle;
pstService->ulRecordLength = sizeof (szSDPRecord);
memcpy (pstService->pRecord,&szSDPRecord, sizeof (szSDPRecord));

pstRegInfo->lpBlob = (BLOB *)malloc (sizeof (BLOB));

pstRegInfo->lpBlob->cbSize = nServiceSize;

pstRegInfo->lpBlob->pBlobData =(unsigned char *)pstService;

pstRegInfo->dwSize = sizeof (stRegInfo);

pstRegInfo->dwNameSpace = NS_BTH;

WSASetService (pstRegInfo, enServiceOp, dwControlFlag);

Posted by: bludev at February 8, 2005 09:18 AM

I want to send/recive some at commands with my mobile using bluetooth and I do not know how to bite it through. Could you help me and put some exemple code of send command?

Posted by: mazZgi at February 14, 2005 05:58 PM

(with->to)Sorry for this mistake:)
This program should stand on the pc side.

Posted by: mazZgi at February 14, 2005 08:42 PM

hi.. i have a problem regarding the platform sdk for xpsp2.. i have "unresolved external symbol" error on all winsock commands in vc++ 6 and "error spawning cl.exe" in vc++ .net.. how do i solve this? i have already registered the platform sdk for vc++6 and vc++ .net.. please help me.. i need to write an app that sends a text file from windows xp w/ embedded sp2 pc to a mobile phone (6600) via bluetooth.. i'm running out of time.. if anyone of you have a sample code please send it to me.. preferrably in vb.net..

Posted by: rough_divide at February 22, 2005 07:19 AM

Hi!
First of all: Thx for the code, it is possible, that you saved my life ;). My first question is, that can you send me the proper version of the uuid.lib, with a small help, that what should I exactly do with it? My second is for everybody: I've read over this topic, and I noticed, that some of you could do file transfer, as well. Can anybody send me, or post a code which realize it too? Thx a lot!

Posted by: AndreW at February 23, 2005 01:18 PM

I am trying to write a client for xp, Thanks for your code it looks like it will be a great help in understanding Bluetooth sockets in XP. I have a D-Link DBT-120 dongle, I was reading above that people couldn't get it to work. Got it working with your program, and it seems to work great so far. Heres how I got it to work. I have Xp Pro SP2. I just installed SDK (http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm) After installing SDK I changed the driver for the dongle. Let XP do a search for a driver and it should choose to use the generic one with the emulator. Then the program works great and I can recieve stuff from a linux client over bluetooth.

Posted by: muldr2 at February 24, 2005 12:42 AM

Hi again!
Hmm, I thought It is going to be easier to get this code worked (I had to realize that I'm quiet unexperienced in this question). So here is what I've done, and please tell me if I done anything wrong: (I have an XP with SP1) I've downloaded the latest platform SDK (it is for sp2), I registered it for my VS. NET. I create a w32 console application project in VS.NET(language: C++), and paste the code into the .cpp source file. If I had a WinXP "comaptible" Bluetooth dongle, than I'm ready, right? Or not? What else I should I do to use this code? Thx in advance!

Posted by: AndreW at February 24, 2005 01:54 PM

Hey,

as people still ask me for help, i decided to drop in to say, the main trick i used to get BT working was installing the mircosoft bluetooth stack even for dongles which ship with the widcomm stack. If you want to code using the widcomm stack, you have to buy some expensive SDK. On the other hand, the MS SDK ist for free ...

Greetings, Ronald.

Posted by: Ronald Nölte at February 25, 2005 11:39 AM

Hi
I'm beginer in programming and I want to programming comunications between two PDA devices by Bluetooth.What I must check before starting programming this problem?Can I use Bluetooth Socket code?
thanks

Posted by: dodyk at March 1, 2005 02:49 AM

I'm beginer in programming and I want to programming comunications between two PDA devices by Bluetooth.What I must check before starting programming this problem?Can I use Bluetooth Socket code?
thanks

Posted by: Gursimran at March 1, 2005 05:44 PM

Hi ya'all

I am totally lost! I am reading, reading and reading, and still I find the overall technology difficult to understand.

I have a bluetooth enabled PC that needs to connect to the in-range bluetooth enabled PDAs. The PC should query each PDA in turn. The flow for each PDA should be:

Do you have any files for me?
yes: get each and one of them
no: ok, buy!

I can make it work to one PDA by adding the PDA in the control panel (under bluetooth devices), and after that by hardcoding the serial ports in my program. To make the serial conn. work, I make a server on the PDA, and a client on the PC. But this ain't gonna work in real life. (bc the hardcoding)

What do I need to do... I have no clue! I looked into OBEX, but it seems that my PDA does not support GET file(can that really be true). Peter: How can I modify your example to support serial comm.

Posted by: Gooky at March 2, 2005 10:40 PM

Thanks for above example.
After so long time, i finally found a forum to talk about write BT app with ms sdk.

After reading all the post above, someone actually posted the question abt using socket by L2CAP instead of RFCOMM( example, socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM) ) before but no one reply yet. So does anyone know abt it? I also want to use L2CAP layer instead of RFCOMM.

Thank you.

Posted by: CS at March 4, 2005 03:41 AM

Hi to all of you guys up there:-).
In attempt to find a solution to get back to work my bluetooth dongle (IOGEAR GBU201) I came across your forum. I'm not a programmer, rather a bit advanced user. This bluetooth thing worked fine before I reinstalled my XP from scratch to an updated SP2 version (realized it was a big mistake). Now I can only send files one way from PC to device and it would not work the other way. I think there's a conflict with native support for bluetooth within XP SP2 and IOGEAR's supplied drivers. Their tech support is pretty much useless. I would appreciate any of your input here if you could give me an ideas. I'd like to completely rid of native XP bluetooth thing for now and don't know where to look. Then I will try the drivers that came with my dongle and see if they work again.
Cheers all.

Posted by: Alex at March 5, 2005 06:56 AM

I have the same problem as CS. I'm trying to establish a L2CAP connection to a bluetooth device (the BlueMP3) running a proprietary protocol based on L2CAP.

In the ws2bth.h header file, there is a BTHPROTO_L2CAP definition and a comment in the SOCKADDR_BTH structure saying that the port entry can also be used as the L2CAP PSM number.

But when trying to create a socket using BTHPROTO_L2CAP, I get a "protocol unsupported" error.

Also, at MSDN, there is no useful information regarding L2CAP, just a bunch of articles that apply to different WinCE versions.

If anyone knows more about this, please tell!

Thanks in advance

Roland

Posted by: RW at April 6, 2005 06:06 PM

Is there a way to make it using Visual Basic.NET?

Posted by: Federico at April 8, 2005 08:22 AM

Dear Sir,
I am having problem to access bluetooth device , using Win32 api , is there any link from where i can get library or information about blue tooth so i can go further in it .
thanks

with regards
Rahul Dubey

Posted by: Rahul Dubey at April 8, 2005 10:25 AM

Hi Len,

Thanks for your code.
Is there any easy way to get to the virtual COM port number that a device is attached to for a device using the COM0 protocol

Gary

Posted by: Gary at April 11, 2005 11:37 PM

Len, Thanks for the example code. works using Belkin F8T001 Vers. 2 adapter.

The only strange thing is it finds BT devices that are no longer switched ON !
Example: it find my iPAQ as Pocket_PC even when the iPAQ is turned off and 60 miles away !

Is there stuff in the WSA... that perhaps is usin