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 (434) | 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 using the registry ?

Posted by: Hans Wedemeyer at April 12, 2005 12:08 AM

Hi,

I'm not surprised that Len hasn't posted in a while. The whole world and their friends have been throwing a ton of Bluetooth questions at the poor guy.

Firstly, check that your Bluetooth Dongle/card is supported through the Microsoft Bluetooth Stack. There is a page on their website (try Google) I've seen it.

Secondly, if your device is not on that list then unfortunately you won't be able to use the APIs written by Microsoft. I suggest looking at Atinav AveLinkBT Windows SDK or if you have a shed-load of cash then you could purchase the WidComm BTW SDK. If your device was on the list then we're in business but you will need the following:

1) Visual Studio (I am using .Net 2003)
2) Microsoft Platform SDK (The only one you can download now is the MS XP SP2 Platform SDK so that might mean you also need to upgrade your WindowsXP to Service Pack 2 - very unfortunate!)

If you have the above two components, and your dongle/card is compatible then copying and pasting the code at the very top of the page should compile with no errors.

There is actually a huge bottleneck in Bluetooth development caused primarily by the company I mentioned before - Widcomm. The majority of Bluetooth devices released use the Bluetooth stack developed by Widcomm (now Broadcom). They charge so much money for the SDK that only business would be able to afford the SDK. I think this is totally ridiculous.

Anyway, good luck with Bluetooth programming.

Rich ;)

Posted by: Rich at April 12, 2005 09:49 AM

Actually I haven't posted for a while because I've been skiing more than I've been coding... That's about to come to an end so normal service will resume real soon now :(

Posted by: Len at April 15, 2005 04:27 PM

I need to check if a bluetooth device is still reachable after a disconnect. I use the following code:
// addressPortPair=(00:11:9f:5a:07:66):3
bool AddressServiceIsReachable(string addressPortPair)
{
WSAQUERYSET querySetPeer;
memset(&querySetPeer, 0, sizeof(querySetPeer));
querySetPeer.dwSize = sizeof(querySetPeer);
GUID protocol = L2CAP_PROTOCOL_UUID;
querySetPeer.lpServiceClassId = &protocol;
querySetPeer.dwNameSpace = NS_BTH;

querySetPeer.lpszContext = (LPSTR)addressPortPair.c_str();
HANDLE hLookupPeer=NULL;
DWORD flags = LUP_FLUSHCACHE;
int result = WSALookupServiceBegin(&querySetPeer, flags, &hLookupPeer);
if (result)
{
return false;
}
WSALookupServiceEnd(hLookupPeer);
return true;
}

It works...but sometimes WSALookupServiceBegin fails with error 10108 (WSASERVICE_NOT_FOUND). I try to poll every 10/50/500/1000/2000 ms and the error occurs every x sec (x = random).
I'm using a TDK device and a Nokia 6820 or 6230.
Any idea?

Posted by: Ettore at April 18, 2005 08:45 AM

Hi guys, I have tried the code on XP SP1 but still facing the SOCKET problem. I understand that this issue has been raised very much earlier. However, I would like to confirm once again that there is no way to work around this?

Posted by: Sean at April 19, 2005 08:43 AM

Dear All,

I have try to run Len's code in winxpsp2 but it hung in accept(), is there any way you could tell me the link for Q323183_WXP_SP2_X86_ENU.exe ?, i want to run the code in XP sp1 but i need the patch

Thank in advanced
noeno

Posted by: noeno at April 26, 2005 11:48 AM

hi guys,

i just searched from the google and found the location on Q323183_WXP_SP2_X86_ENU.exe, the link is still active ;)

http://download.microsoft.com/download/whistler/SP/1.1.1/WXP/EN-US/bt_stack_rtm.exe

so have fun with XP sp1 bluetooth stack

noeno

=====
i'm wondering what happen in bluetooth stack in sp2, the wsasetservice is not working.....

Posted by: noeno at April 26, 2005 04:26 PM

Hi Len,

I've tried your code on two cellulars: Nokia 6600 and 6230. It works well with 6230. But with the 6600, the prog is breaking when it comes to the services: it displays "SDP Server" then exit with an error.
Do you know if there is any incompatibility with this cellphone (it works well with the microsoft bluetooth panel of xp sp2) ?

Regards.

Posted by: JPH at April 27, 2005 10:20 AM

The code is just a simple example, it's not production ready code. It probably just needs debugging...

Posted by: Len at April 27, 2005 03:44 PM

Len,
i just tried to use your code under xpsp1 with the bluetooth patch, i use CSR, but my k700 could not found any service available on my PC, but the funny thing is my friend's z600 able to find it by acident

:(


could you please give me your bluetooth server code

thank you

Posted by: noeno at April 27, 2005 06:18 PM

No ;) But we might sell it to you...

Posted by: Len at April 29, 2005 04:40 PM

I noticed you have a site about Bemused. We’re working on a cool new open source project called Pluto. It consists of a “Core”: a central media server to distribute movies, music and tv shows throughout the house; a home automation controller for lights, climate, pool, etc.; and a phone system with video conferencing. It also exposes a network boot for “Media Directors” so your PCs can boot off the net as a media player, PVR and video conferencing set-top box without installing software.

The remote control software, called “Orbiter”, runs on Symbian Bluetooth mobile phones as well as Linux, Windows and Windows CE devices like webpads and pda’s. They all feature cover art, interactive maps and floorplans, and let you control any device in the house. The UI is skinnable and multi-language. The mobile phone has a ‘follow-me’ feature so your media and other settings follow you from room to room. When you leave the house, it switches to gprs/wap. So the instant something happens at the house (burglar, doorbell, etc.) you get a live video feed, can control the house, and speak to the person through the stereos. It also includes a plug-and-play back-end for Squeeze Boxes, IP phones and cameras.

Check it out at plutohome.com. It’s already useable. If you or anybody else on the Bemused team would like to work with us on a bridge so Bemused and Pluto can work together, or add support for other types of phones, we have forums or you can email our Symbian developer at chris.m (at) plutohome.com. So far everybody who sees our project is pretty impressed, and we’ve got a lot of guys working on it, but not very many people know about it. If you think it would interest your users, we’d appreciate any exposure.

Posted by: laura.c at May 16, 2005 06:07 PM

Hi, Len 8))

Can I use SDK's included in MS VS.NET 2003 to compile and run this code?) Or I must download Platform SDK only from the site? I have very slow connection to the i-net and it's awfull for me to download 200 Mb.

Thanks for helping 8))

Posted by: AzuManga at May 18, 2005 06:35 PM

I don't know. Try it and see.

Posted by: Len at May 18, 2005 07:03 PM

Hi again, can anybody answer how can VS .NET or VS 6.0 see h-files from installed Windows SDK? When I try to write C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include in Additional Include Directories nothing is happening 8(

What should I do?

Thanks for helping me 8)

Posted by: AzuManga at May 21, 2005 04:40 PM

Hi Len and all,

I have installed sp2 on my xp desktop machine,
and tried the code posted by len on .Net,I am getting error message with code 10108 after WSALookupServiceBegin. I am using Bluetooth USB Dongle.

Can anyone plz help me ..to fix this.

Posted by: help at May 31, 2005 05:19 PM

After this call:
int result = WSALookupServiceBegin(&querySet, flags, &hLookup);
The debug window reports this error:

First-chance exception in test.exe (KERNEL32.DLL): 0x00000006: (no name).

Any idea why ?

Looks like some unfinished code at the end of the example:

These two calls generate error "The specified module could not be found."

Any idea why ?

if (BluetoothGetDeviceInfo(hRadio, &deviceInfo))
{....}

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

Posted by: Hans W at June 5, 2005 07:18 PM

The debugger will always display first chance exception messages even for exceptions that are handled by the code you're calling. So, if the exception doesn't actually make it out into your code you're usually OK. The exception may be part of normal processing for that particular code path.

No idea re your other problems.

Posted by: Len at June 5, 2005 07:30 PM

I have a pocket pc 2003 mobile phone (sprint PPC6600) and it has the dreaded widcomm/broadcom bluetooth stack. The windows WSALookupServiceBegin fails with 10108 like several other folks have noted. I assume that this means the only recourse I have is to use serial I/O, or is there any other way to tackle this problem? I don't want to buy the broadcom API, and I think selling the broadcom stack to CE vendors without supporting the MS api's is nearly criminal.

Posted by: Terry at June 16, 2005 06:46 AM

Hi Len,

I have been tried to compile your code with the MSVC++6 but i got error :
uuid.lib(bthguid.obj) : fatal error LNK1103: debugging information corrupt;

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,

could you upload or email the version of uuid.lib that worked for you? or do u hav any other ideas?

Thanks in advance
noeno

Posted by: noeno at June 16, 2005 03:43 PM

Len,

Thanks for your uuid.lib, i have success compiling your code, btw i just notes that the firmware version for csr dongle that will work with your code and SP2 is below 829 i have made several test with my buggy k700 and other mobile phone, so for those of you who wants to develop the code make sure that your bt dongle f/w not higher than 829

Len, another thing, do you have any code for advertizing SDP with blob (binary), i have try but always got error 10022(invalid argument supplied)

once again Len, thanks for your briliant code

noeno

Posted by: noeno at June 17, 2005 09:22 AM

Noeno

Glad it works. I haven't tried advertising SDP with binary data. Sorry.

Posted by: Len at June 17, 2005 09:27 AM

" fatal error LNK1103: debugging information corrupt"

if you get that error, try compiling it as a 'release' version instead of a 'debug' version.

Posted by: Gar at June 28, 2005 03:28 PM

Hello,

There was a question posted earlier by a Hans Wedemeyer regarding the fact that the code above still finds devices after they have been switched off. Further more if I change the Id of my phone this is not updated when I re-run the program. Is there a cache of some sort that needs to be cached?

Cheers,

James

Posted by: James at July 4, 2005 02:46 PM

Yes, there's a cache. Look at the MSDN docs for WSALookupServiceBegin (the code above should flush the cache and issue a real device enquiry going by the flags that I'm passing in) and also look at the docs for BluetoothFindFirstDevice and the search params structure; we set the flag to return from the cache and NOT issue a new enquiry...

Posted by: Len at July 4, 2005 02:56 PM

Thanks for the quick response, this website has been an oasis of information in a desert of blueteeth.

Cheers,

James.

Posted by: James at July 4, 2005 05:36 PM

Hello again,

I've been playing about with the server code and the only way I can receive messages from my nokia phone is to run your server app, then right click on the bluetooth icon on the task bar and select receive a file and then send the file from my phone. If i don't select the 'receive a file' option my phone cannot detect any devices to send to. Is this normal? and can I use the bluetooth functions to programmatically select the 'receive a file' option?

Cheers,

James

Posted by: James at July 7, 2005 03:23 PM

Hey Len,

thanks for this coding anyway, I'm not a real C/C++ programmer as my company uses Clarion 6 (www.softvelocity.com). The Clarion SDK allows you to interface with C/C++-DLLs as well as the native Windows DLL. There might be some trouble prototyping the functions and variables but all in all you can do it.
Right now my job is to write an app that comunicates with a Bluetooth device in an aeroplane that stores flight-infos. The device uses the BT-RS232 protocol. As Clarion does not support BT or the WIN-BT API natively I have to do it from scratch, so your code is very very helpful. But I don't really understanding everything as I'm not - as I mentioned - a native C/C++-programmer. So do you think you could add some commments to the code so that I can get the clue?

Thank you anyway,

Nick

Posted by: Nicolas Ott at July 14, 2005 12:19 PM

Nicolas

I'm sorry but I don't have time to turn this simple sample into a tutorial.

If you'd like me to quote for doing this for you then we can do so.

Posted by: Len at July 14, 2005 01:52 PM

Hey Len,

thanks for the quick answer. I'll think that over!

Cheers, Nick

Posted by: Nicolas Ott at July 14, 2005 05:52 PM

Hi! I'm getting a 10049 ("the address is invalid in its context") when attempting to bind the socket for bluetooth service advertisement. This is what I do:

SOCKADDR_BTH name;
SOCKET hServerSocket = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

name.addressFamily = AF_BTH;
name.btAddr = 0;
name.serviceClassID = GUID_NULL;
name.port = BT_PORT_ANY;

if(::bind(hServerSocket, (sockaddr*)&name, sizeof(name)) == SOCKET_ERROR)
{
// This is where I end up
}

Any ideas?

Regards,
Nille

Posted by: Nille at July 20, 2005 11:56 AM

The reason you get an INVALID_SOCKET error is probably because you dont have appropriate drivers installed for your device. Read the comments here and on the other bluetooth entry here: http://www.lenholgate.com/archives/000089.html

Posted by: Len at July 20, 2005 12:21 PM

Hi Len,

I am trying to develop a client (Pocket PC 2003)/server (Windows XP SP2) application via the WinSock support for Bluetooth. I am stuck with the connect call, which always fails and the WSAGetLastError call reports WSAEINVAL. I went through this page and could not find a similar the same topic.

The Pocket PCs are the latest HP iPAQ and Dell Axim. They have built-in Bluetooth support. The USB Bluetooth adapter I am using on the XP is the D-Link DBT-120. Here is what I did.

On the server side (XP), the socket is created, bound, and started listening. Then the server advertises the service with my own class ID(NGW_TERM_SVC_ID) generated from the Windows utility GUIDGEN.exe. Finally, it starts to accept connection requests. Everything seems OK.

On the client side, the socket is created via the call:

SOCKET Socket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

The address is specified as:

SOCKADDR_BTH BthAddr = {0};
BthAddr.addressFamily = AF_BTH;
BthAddr.btAddr = Addr; // CE 51 5F 3D 0F 00 00 00
BthAddr.serviceClassId = NGW_TERM_SVC_ID;

Finally, the client tries to connect:

connect(Socket, &BthAddr , sizeof(BthAddr));

The call always fails with the error condition WSAEINVAL.

I want to know what I did wrong or what steps I missed? The MSDN document seems to be incomplete and inconsistent. I am stuck and really frustrated. Please give me some help! Thanks a lot!

Posted by: Xiaoan Lu at July 26, 2005 10:06 PM

i am not getting wat is the problem with my system.the error is coming in c programming which is that "unable to open file stdio.h" why it is coming .as all the header files are define in the system when loaded.when i search for a topic stdio.h then it shows no topic found.plz suggest me

Posted by: ashu at August 10, 2005 09:31 AM

hey len. Can you please explain to me or point me in the direction of some documentation on the difference between the code u use with sockets to list devices and their services and the code to do with radio that just lists devices. Whats all the radio stuff for? and why have 2 ways to do the same thing?

Posted by: andy at August 31, 2005 04:38 PM

Andy

I've no idea why there are different ways to do it but I expect it's just because the winsock level code allows full access to everything you can do and the BluetoothXXX Api is a wrapper that exposes things that the Api writer thought were useful...

Posted by: Len at August 31, 2005 06:35 PM

hey len thanks for the response, I'm having trouble outputting the service ID any chance of an example?

Posted by: andy at September 2, 2005 03:01 PM

I have a problem! Where can I find btdrt.dll file? I red in the platform SDk but there isn't nothing!!
Thanks

Posted by: Marco at September 6, 2005 05:38 PM

I did a search on Google and it seems that the dll you are looking for is for Windows CE, are you looking in the correct SDK?

Posted by: Len at September 6, 2005 08:46 PM

i want to know what are the codes in VB 6.0 to communicate through BlueTooth.
plz reply through mail as soon as possible...
thanks
regards
Ambuj Pandey

Posted by: Ambuj Pandey at September 15, 2005 07:26 AM

hi,

i am developing a simple app for pc to pc comm using bluetooth using vc++ 6.0 and winxpsp1.can i get some sort of code for recieving and sending data?

Posted by: saumil at September 19, 2005 07:31 AM

Once you have a socket connection using the code on this site you can use normal socket code to communicate.

Posted by: Len at September 19, 2005 08:26 AM

when i do discovery it works fine except for any nokia device it finds with services running, it just lists the first service which is SDP Server and then the application crashes. :( it works fine for all other BT devices, any ideas?

Posted by: neo at September 20, 2005 10:28 AM

Where does the application crash? Debug the application, perhaps it doesn't handle this kind of service correctly? Or is the crash within the bluetooth api/winsock code?

Posted by: Len at September 20, 2005 10:42 AM

hi again,

i have a d-link bluetooth device with a widcom driver.Is this compatible with windows xp api for bluetooth sockets.If not are there any other drivers that i can use . Thanks.

Posted by: saumil at September 21, 2005 07:01 PM

hi len,

i cant find the pc to pc bluetooth socket code you mentioned could you please send me the links.Thanks a lot.

Posted by: saumil at September 22, 2005 06:34 PM

What PC to PC code?

Posted by: Len at September 23, 2005 12:05 PM

Hi!

I have T-Mobile MDA Compact. It is pocket with GSM and BT. There are more names for it :) (QTek S100, HTC Magician, i-Mate Jam).

I would like to sit on my sofa and tap screen, lets say icq or irc, or mail, or like... and be connected.

After few hours of searching for someking of tcpip over BT it seems there isn't any. OR maybe there is?
Oh, if you (anyone) have it, or have slight idea where it could be found... please... :)

Well, this page is quite long, and it seems that sockets are working. Now, I'm thinking about creating virtual NIC for win ce and win that would encapsulate tcpip and transfer it over BT.
Would that be possible?

thx

Kristijan

Posted by: Kristijan at October 25, 2005 01:18 AM

I am also suffering from the problem of uuid.lib I am now using winxp sp2 with latest platform SDK installed. When compile your bluetooth program , the uuid.lib problem come out. I have check my uuid.lib is from platform SDK library directory. But the problem still there.

Could you mind sending me your uuid.lib to me? Also why this problem happen and will this repeat when i install my program to another xp computers?

Many Thanks
Mike Lee

Posted by: Mike Lee at October 25, 2005 12:36 PM

Mike


The uuid.lib file is only used during linking. It's not required when the program is running so the problem will not affect anyone that needs to run the application once it has been built.

I'll install the latest platform SDK and see if I get the same problem. I've just realised that the current platform SDK that I have installed is the Feb 2003 one and that works fine.

Len

Posted by: Len at October 25, 2005 12:47 PM

It looks like the cause of the uuid.lib problems is that the last Platform SDK to support Visual Studio 6 was the Feb 2003 one. See here: http://www.eggheadcafe.com/ng/microsoft.public.platformsdk.sdk_install/post21031929.asp for details.

If you have an MSDN subscription you can probably still download the Feb 2003 SDK if you need to use Bluetooth with XP and you want to compile with Visual Studio 6. Bear in mind that VS 6 is (as of the end of Sep 2005) no longer supported by Microsoft.

Posted by: Len at October 26, 2005 11:13 AM

excellent

Posted by: at November 28, 2005 10:28 AM

Hi.
A big thanks goes to the author of this article.
Implementing a bluetooth file transfer to mobile devices was much easier after reading your example.
My question addresses the changing of radio name when a connection with a remote device is established. Is there any way of modifying the name of your radio except changing computer's name? (together with a restart, of course)
I didn't find any function in MS api.
Is this all depending on where the dongle keeps system info? (like registry or some ini files)

Thanks again.

Posted by: Horia at December 2, 2005 12:30 PM

Firstly Thanks to Len for writing such a useful piece of code.. !!!!

Hey guys

All of you who are facing problems with UUID.lib which comes from older version of SDK. Here is a solution !!!!

You can download the old SDK from MS site itself..

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm

Install it..

In your VC++ 6.0 IDE go to tools->options->Directories->

select library files and provide path as
C:\Program Files\Microsoft SDK\Lib
( or path where you have installed your SDK)

Move this path top in the selection hierarchy.

It should get you rid off "uuid.lib(bthguid.obj) fatal error LNK1103: debugging information corrupt"

Write to me if u need anymore info. for getting rid of this error.

Thanks Len once again

Jay

Posted by: Jay Sharma at December 3, 2005 01:50 AM

Thanks Jay, I wasn't aware that the Feb 2003 Platform SDK was still available for download!

Posted by: Len at December 4, 2005 11:57 AM

Hi,
Im with sockets programing.i am stuck with the server part.it would be really usefull to me if you could send me some example codes to build up the server socket for series 60.Im working in code warrior ide..thanks and regards
Priju

Posted by: Priju at December 16, 2005 06:06 AM

Drop me a mail and we can discuss your requirements and I'll send you a quote for the work...

Posted by: Len at December 16, 2005 09:44 AM

Hi,

I need your help guys.
I am writing an application for windows using VC++/MFC. My company produce a Bluetooth device that use the SPP service.
I am looking for a way to automatically or through the software to connect the pc to the SPP service of the device and assign a virtual serial port, which my application will communicate with. the solution

I am looking for should not be depended on which Bluetooth stack the user pc use.

any idea?

Thanks in advance,
Oren

Posted by: Oren at December 20, 2005 01:58 PM

Hi Everyone, I wish to clarify something before I actually install Platform SDK.
1) The code given by Len is for the Desktop Application to advertise the services to the iPaq?
2) I need to write a application to let the iPaq communciate via the bluetooth emulated ports, will I able to achieve what I want in Platform SDK (since it is usually for writing desktop application [please correct me if i am wrong])
3) Configuration
Desktop using Microsoft Bluetooth Stack
iPaq 1940 using Widcomm Bluetooth Stack Version 1.4.1 Build 04

Please enlighten me.
Thank you!
Clement

Posted by: Clement at December 21, 2005 05:17 AM

Clement

1) Yes.
2) No. You need a version of visual studio that supports the iPaq (maybe a version of VS.Net if you want to use the compact framework, or the embedded vc if you want to use C++).


Posted by: Len at December 21, 2005 07:26 AM

Hi Len,

Thanks for your replies.
The problem now lies in writing the iPaq application to use the emulated ports.
I just use win32 api CreateFile to open the port and the iPaq ask me to choose the select the BlueTooth device. When I select my PC, there is an error message "No Bluetooth serial ports could be found for device xxx".
I have configured the incoming and outgoing ports from the COM Ports Tab from the Bluetooth Devices.
Here is what my program does
1) RegisterDevice btd.dll (Do I have to do this step?)
2) But I got a 0 for this device and I cannot seems to find this dll in my iPaq.
3) Open the Com Port 5 which is stated as the outgoing COM Port from the Bluetooth Serial Port Tab from the iPaq. I got the error opening the COM Port and Error Code 55 which means "The specified network resource or device is no longer available."
4) The COM Ports are COM6 Outgoing PocketPC 'Generic Serial' and COM13 Incoming PocketPC.
I read somewhere saying Bluetooth Serial Ports cannot be 2 digits coz ActiveSync cannot recognise it? http://www.theunwired.net/forum/viewtopic.php?id=992

Please advise.
Thank you
Clement

Posted by: Clement at December 22, 2005 02:44 AM

Clement

I've no idea, sorry, perhaps someone else here can help?

Posted by: Len at December 22, 2005 08:20 AM

Hi Len,
I have solved my problem.
First, I paired my Bluetooth device with my iPaq PocketPC.
Secondly, I used OpenNETCF Serial API to open a COM Port 5 and it works.

Thanks
Clement

Posted by: Clement at December 29, 2005 01:27 AM

Clement,

Cool!

Posted by: Len at December 29, 2005 09:57 AM

Hi all!

I'm not really a programmer, though I dabble a little with Visual Basic. I'm looking for a programmer who can write a very simple application for me that will simply report the BT address of any devices in range. It has to cycle indefinately without user intervention and can be pretty flexible about how the addresses are returned but ideally there would be some kind of VB interface or even a time/date stamped text file for each address would do... Maybe some way to call your routine from my (primitive) VB code? Simpler the better! A nice to have would be a programmable time period for the discovery cycle but that's not so important.

Any takers please contact me at vitchling@hotmail.com

I use a MSI BToes USB BT dongle, XP Home SP2 and VB6

Thanks!
Andrew

Posted by: Andrew at January 5, 2006 05:09 PM

I am trying to create a server-client application. I ran the code you supplied that queries the device, and it works fine.

My Server just waits for someone to connect it, and it runs fine.

I've binded to the socket for the server with:
SOCKET m_socket;
m_socket = socket( AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM );

_SOCKADDR_BTH name;
name.addressFamily = AF_BTH;
name.btAddr = 0;
name.port = 15;
bind( m_socket, (SOCKADDR*) &name, sizeof(name) );
listen( m_socket, 1 );

SOCKET AcceptSocket;
while (1)
{
cout

Posted by: France at January 16, 2006 12:04 AM

.... Continued from above ....

SOCKET AcceptSocket;
while (1)
{
cout AcceptSocket = SOCKET_ERROR;
while ( AcceptSocket == SOCKET_ERROR )
{
AcceptSocket = accept( m_socket, NULL, NULL );
}

cout m_socket = AcceptSocket;
break;
}

Now, I believe this server works fine, since there are no errors when I check all the return values for the call.

Posted by: France at January 16, 2006 12:07 AM

Continued from above ....

My Client however fails to connect,
SOCKET m_socket;
m_socket = socket( AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM );


_SOCKADDR_BTH clientService;
clientService.addressFamily = AF_BTH;
clientService.btAddr = 0;
clientService.port = 15;

if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)
{
cout WSACleanup();
return 3;
}

I do not know how to retrieve the correct details for the client to conenct to from the remote server

Posted by: France at January 16, 2006 12:08 AM

What you seem to be trying to do is use the 'well known port' style of socket connection that is standard for TCP/IP etc. This would require that your client knows the address and port that the server is listening on... Bluetooth generally uses a 'discovery' based method. Your server should use WSASetService to advertise its service and your client could then use the standard discovery techniques to locate the server.

Posted by: Len at January 16, 2006 07:46 AM

Ok, so I added this into the the server after it listens and before it accepts (this was found in comments above posted my you).

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 = sizeo (SOCKADDR_BTH);
csAddr.LocalAddr.lpSockaddr = pAddr;
csAddr.iSocketType = SOCK_STREAM;
csAddr.iProtocol = BTHPROTO_RFCOMM;
service.lpcsaBuffer = &csAddr;
service.lpcsaBuffer if (0 != WSASetService(&service, RNRSERVICE_REGISTER, 0))
{
printf("%s\n", GetLastErrorMessage(GetLastError()));
}

Then I use my client to query services, but I never get a service with the name "My Service", but instead I only every get one service, which is the hostname of the other computer, that has a dongle plugged into it.

Posted by: France at January 16, 2006 10:26 PM

There's really no need to keep posting vast amounts of code. I don't look at it. I don't have time to debug your code for you.

Anyway, does your client device support the FileTransferService? Can it see FileTransferService from other devices? Do you have other potential clients that can see and use the FileTransferService (such as a PDA)?

Then you have the question, is the FileTransferService really what you want to be advertising? Are you intending to support the OBEX protocol that's necessary? It might be better to advertise something like a serial port or something where you'll just be expected to send and recv bytes...

Posted by: Len at January 17, 2006 07:55 AM

Hi, I use the great code that Len provided.
I use MSI-bluetooth dongle with its Microsoft-Windows compattible driver and I have an icon "Bluetooth Devices" in the control panel.
The problem is that I cant connect or send dada to my Nokia-6230. The program recognises my Nokia-6230 and sees its services but whenn Im trying to connect the connect function returns (-1) and the error code from GetLastError() is 10022.
Im totally desperate and can't solve this problem. does any body have a clued? any help will be appreciated.
pleas help me...

Posted by: tc at January 25, 2006 09:22 AM

Hi Len it seeems like you have deserted this issue, ... or maybe there is no answer for my problem?
pleas let me know if you dont have a clue or you just dont have the time.
Hope to read from you soon.
Lots of thanks..., tc.

Posted by: tc at February 2, 2006 07:11 AM

is ther any body out there ....? .. ?.. ?.. ?....

Posted by: Nobody at February 5, 2006 12:24 PM

I have the same problem, but it seems like no one is readding this thread, we have to solve it by ourselves, so by, this file is no help and no one is reading it,... by by ...

Posted by: OneOfYou at February 5, 2006 01:51 PM

TC, Nobody and OneOfYou...

I've been away on holiday.

Perhaps you should try and help each other solve your common problem. I don't have a Nokia-6230. Personally I'd start by looking up the error code as often that's helpful when trying to determine what's wrong.

I don't have the time to investigate your issue for free, if you'd like some consulting then get in touch and I'll quote you a rate and schedule you some time.

Posted by: Len at February 5, 2006 02:56 PM

Sory, I just thought it is some kind of a forum in which developpers share their comments, I didnt know that you are the only one that share his knowledge on this thread and that it cost mony to share it with you. Moreover, it is obvious that on the same thread you can get answers for your own questions, after all I belive you dont know everything.
Nevermind, the time is yours and you are the only one to decide on how to share it, thanks anyway, ... regards, OneOfYou .

Posted by: OneOfYou at February 6, 2006 08:34 AM

I answer questions when I can. Often mine or other people's comments help other readers. If you look at the top of this thread you'll see that the original article was posted in 2003. If you search the rest of this site you'll see that I haven't done a great deal of work with bluetooth on XP since then (the original client request came to nothing). I simply don't have the time or inclination to write your code for you for free. Sorry, that's just the way it is.

Posted by: Len at February 6, 2006 08:57 AM

Hi Len, I certainly don't want anyone to write my code; I just posted a question which may be easily answered by a skilled bluetooth-sockets programer:
1. is it possible that this problem is related to the BT-dongle? ... or it is defenetlly a problem with my code?
I believe that it can't be related to a specific phone or device that I have since the device conform to the bluetooth protocol; Moreover, the 6230 device communicate with the PC and enable file transmission with the use of different programs.
Anyway, it is important for me to note that,
NO MATTER WATH OTHERS SAY .... I AM GRATEFUL FOR YOUR HELP, you have certainly added a great amount of information and helped me a lot as a begginer with bluetooth sockets.
Lots of thanks..., tc.

Posted by: tc at February 6, 2006 04:42 PM

TC

Step one in your quest for an answer would be to look at what 10022 means as an error. Looking in Winerror.h gives this

//
// MessageId: WSAEINVAL
//
// MessageText:
//
//  An invalid argument was supplied.
//
#define WSAEINVAL                        10022L

and without seeing your code I couldn't begin to tell you what you're doing wrong and I don't really have the time to look at the code and solve the problem for you.

Posted by: Len at February 6, 2006 04:49 PM

Len, your comment "It might be better to advertise something like a serial port or something where you'll just be expected to send and recv bytes..." just help me.

Thanks a lot.


Posted by: derek at February 7, 2006 10:37 AM

Derek

Cool. Glad I could be of some help.

Posted by: Len at February 7, 2006 10:46 AM

Im sorry Derec I didn't understand your comment. Actually, I didn't understand if it is assumed to be an error in my code or a problem with my bt-dongle/driver.
Pleas recall that:
I use MSI-bluetooth dongle with its Microsoft-Windows compattible driver and I have an icon "Bluetooth Devices" in the control panel.
The problem is that I cant connect or send dada to my Nokia-6230. The program recognises my Nokia-6230 and sees its services but whenn Im trying to connect the connect function returns (-1) and the error code from GetLastError() is 10022, which is "An invalid argument was supplied".
So the main question is:
is it an error in my code, or is it the bt-dongle (or bt-driver) ????
Lots of thanks, TC.

Posted by: tc at February 8, 2006 08:54 AM

TC, Derek was replying to an earlier comment.

I would assume that the error is in your code. Do you have any other bluetooth devices that you could try and connect to? Are you using the code from my original article unchanged? If so it's highly unlikely to "just work", it's just example code. Have you tried pairing the pc with the mobile using the usual "Bluetooth Devices" method? Can you access your phone using the usual "Bluetooth Devices" methods? etc.

Posted by: Len at February 8, 2006 09:36 AM

Yes I succeeded pairing the PC with the mobile using the usual "bt-method".
Im using the code from your original article. Its my first time with sockets and I try to understand it while working with it, I tried to add some lines in order to read/write data to my mobile. I don't have any compilation errors. The only problem is that the connect function returns (-1) and causes the error code from GetLastError() to be 10022 i.e. WSAEINVAL.
I "just" want to send and reciev bits or any form of data ..., is it so hard???

Posted by: tc at February 9, 2006 09:10 AM

Is it so hard? Yes. Unfortunately. Though it's more a case of you need to understand the implications of what you're trying to do rather than it being hard. So, are you running custom software on the phone to process these bytes that you want to send? If not, I assume you're conforming to the specification for the protocol that the phone will be using to converse with you? Either way I assume that the protocol is being advertised as a particular service on the phone, are you attempting to connect to the correct service? Etc. Lack of compilation errors means nothing if you dont really understand the code that you've added... The code found here is simply sample code to demonstrate some of the Windows XP SP2 Bluetooth API functionality. It's assumed that to be able to use this you'd already understand the rest of the issues such as the correct use of the Windows Sockets API and the expectations implied by Bluetooth and the devices that you intend to connect to. If it were 'easy' then, to be honest, there wouldn't have been much point in me posting the original code...

Posted by: Len at February 9, 2006 09:31 AM

I started to code serial connection through bluetooth, first I tryed sockets (thanx Len) and it did work ok, but I found out that I have to take care of spliting large amounts of data (let's say 1MB) and send them in chunks. I did remade the code and I'm using CreateFile now to open a bluetooth COM port (it must be the same as Incoming bluetooth COM port) and it works ok too (source code is available at qwerty.qwerty.szm.sk). Anyway my question is: Can I send large amount of data when using sockets without taking care of splitting the data?(maybe I red wrong and it can be sent without splitting it at all)

Posted by: Coroner at March 18, 2006 08:28 AM

Why do you think that you have to split up the data for the socket connection and not for the serial connection? You should be able to use the same technique to send in both cases.

Posted by: Len at March 18, 2006 10:36 AM

Hi,len:
i test the blue.cpp,but when run,it have error:WSALookupServiceBegin() failed with WSALastError = 10108;can you help me?
thanks a lot!

Posted by: ainycao at April 14, 2006 02:54 AM

It's probably best for you to try and help yourself... First find out what that error code actually means...

Posted by: Len at April 14, 2006 08:42 AM

Hi,len:
I have trouble with follow code:

Code:

WSADATA wsaData;
WSAStartup(MAKEWORD( 2, 2 ), &wsaData);
SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
Result: s = INVALID_SOCKET, and GetLastError() return 10047 (address family is not supported).

I run the program in windows xp(sp2),can you help me?

Posted by: scott at April 17, 2006 02:28 AM

Hi,len:
I have a trouble with socket,i write a client and server program ,the connection way is SOCK_STREAM,the client can connect the server,but can send data,and the error code is 0,can you help me,why?what's the meaning of the 0?thanks!

Posted by: scott at April 27, 2006 12:18 AM

i'm sorry,i sad wrong,can't send data to the server by send() function.

Posted by: scott at April 27, 2006 12:20 AM

Hi Len,
I am currently working on Bluetooth Socket programming.
I am working on WinXP SP2, VC++ 6.0, SDK 2003 and "Entermultimedia" Bluetooth USB dongle. I am working on your code. But i am getting bind error(error number 10050). Please help me? What will be reasons? if possible provide me other sample codes also? Plz..... Thanks in advance.

Posted by: Prasad at April 27, 2006 02:21 AM

Step 0 - read all the other comments.
Step 1 - look up what the error code means.
Step 2 - if you still need help, contact me and I'll quote you for some consultancy.

Posted by: Len at April 27, 2006 02:27 AM

You should call GetLastError() (or, WSAGetLastError()) straight after the call that fails; you're probably screwing with the error code by calling MessageBox()

Posted by: Len at April 27, 2006 03:41 AM

I have called the function WSAGetLastError()and get the error code 0,so what's the meaning of the 0,can you help me,thanks!

Posted by: scott at April 28, 2006 01:14 AM

Hi Len,

Currently i am working on Bluetooth sockets programming. I am using VC++ 6, SDK 2003 and WinXP SP2. I want to transfer a file from Mobile to Pc using USB Bluetooth dongle. With OBEXFileTransferServiceClass_UUID, i am able to transfer two bluetooth dongle. What is the service class UUID for file transfer from Mobile to Pc? Thanks in advance.

Posted by: Prasad at May 1, 2006 03:42 AM

I've no idea.

Posted by: Len at May 1, 2006 06:07 PM

Hi Everybody,

Currently i am working on Bluetooth sockets programming. I am using VC++ 6, SDK 2003 and WinXP SP2. I am trying to transfer a file from Mobile to Pc using Bluetooth USB dongle. Is it necessary to have authentication? But both PC and mobile are paired before. Is there any precations while advertising the service by server? Pls help me. Thanks in advance.

Posted by: Prasad at May 6, 2006 10:49 AM

Hi,
Currently I am working on SyncML(Data synchronization between mobile and PC)protocol over bluetooth communication.
What service class GUID i could use for synchronization.
This is the sample code:

WSAQUERYSET service;
memset(&service, 0, sizeof(service));
service.dwSize = sizeof(service);
service.lpszServiceInstanceName = "My Service";
service.lpszComment = "My comment";

GUID serviceID = OBEXFileTransferServiceClass_UUID;//which guid??

service.lpServiceClassId = &serviceID;

Thanks
Prasad.


Posted by: Prasad at May 22, 2006 02:25 PM

I've still got no idea, but maybe someone else can help...

Posted by: Len at May 22, 2006 04:58 PM

Apologies for posting a "nothing" post to this thread but I have to say Len your patience is inspiring. Your code is great and if I have any troubles, I may even try to debug them myself :-)

Many Thanks, Paul.

PS dot com dot au is not questionble form content "Your comment could not be submitted due to questionable content: " it's an Australian domain name.

Posted by: Paul at May 23, 2006 07:18 AM

Paul

Have adjusted my over zealous blacklist to allow .com.au in future...

Posted by: Len at May 23, 2006 09:44 AM

I have try blue.cpp in visual studio 2005.
But i have a problem:
#include
#include
aren't supported in win 32 project.
How can I resolve?

Posted by: desy at May 27, 2006 06:15 PM

Oppssssssssssssssssssssssss!
Sorry,include are:
Ws2bth.h
BluetoothAPIs.h

Posted by: at May 27, 2006 06:17 PM

ps:thanks in advaced for help
by desy

Posted by: at May 27, 2006 06:23 PM

Thanks dude! that was really worth it .. thanks alot

Posted by: Himanshu at June 3, 2006 02:58 PM

Desy,

Do you have the platform SDK installed correctly?

Posted by: Len at June 3, 2006 04:44 PM

Hi Len:
I use your code but get 10047 error, I have read all the above comment, so I know need Microsoft Bluetooth Driver installed in my PC, is it right?
I have WinXp Sp2 installed, and Visual C++ 6.0,
and Bluetooth's Driver has been Installed properly. That's to say I have to Install 2 Drivers with Bluetooth, right? Thanks.

Posted by: Ekson at August 12, 2006 11:53 AM

Hi Len:
On more question, where I can get the Microsoft Bluetooth Driver? Download or Buy it from MS?
Thanks, My E-Mail is itaoi@126.com
My English isn't very good.
Thanks.
:)

Posted by: Ekson at August 12, 2006 11:57 AM

The MS bluetooth stack usually comes with the device that you purchase...

Posted by: Len at August 12, 2006 01:01 PM

Len:
MS Bluetooth stack was automatically installed when I updated to SP2, isn't it?
But I still got 10047 Error, my Bluetooth Port isn't a USB adapter, which is a integrated adapted with my NoteBook, is that the problem?
Could you tell me what shall me to do?
Thanks

Posted by: Ekson at August 13, 2006 01:17 PM

if you get the error then the device isnt supported and you dont have the drivers installed.

Posted by: Len at August 13, 2006 03:00 PM

Hi Len

I am trying to run this code in visual. Net, I hade a problem finding the Ws2bth.h file at the beginning but after looking at this form I have downloaded the SDK platform and I did mange to get the Ws2bth.h file and include in my project, but when I try to build my project I do get this error massage :

fatal error C1083: Cannot open include file: 'Ws2bth.h': No such file or directory

Any help

Regards
Hewa

Posted by: Hewa at August 13, 2006 05:14 PM

You need to make sure that the platform sdk include and lib directories are set up correctly in visual studio so that it can find them.

Posted by: Len at August 13, 2006 07:19 PM

Hi,

not sure if you know, but the Broadcom/Widcomm
SDK for Bluetooth for Windows and Win/CE is now
available for FREE from their Web site.

Dilip

Posted by: Dilip at August 26, 2006 11:34 PM

Hi Len,
I'm developing a Bluetooth UI with VC6.As a Client it could run normally since it could communicate with the other Bluetooth device which UI was provided by D-Link.But when it acted as a Server,it couldn't work.
Bugs:
My UI act as a Server,the other Bluetooth device run D-Link Client mode UI can find it,but Client Mode IO control routine will occur error at once after send "Connect" command,use "int nError = GetLastError()" to check,nError = 10064
and my UI can't receive any events,eg FD_ACCEPT, FD_CLOSE, FD_READ...all the time.
Could you give me some advice or share a Server sample here?
Many thanks!

Qube

Posted by: Qube at August 27, 2006 03:47 AM

Hi all,

For bluetooth develp,my OS is Winxp SP2 and I have installed Microsoft Platform SDK.
Any other softwares need to be installed?

Thanks

Posted by: Arthur at August 27, 2006 05:10 AM

That's useful information, thanks Dilip.

Posted by: Len at August 28, 2006 02:52 AM

Qube,

Sorry, I don't have any time to develop any more sample bluetooth code for free. Maybe someone else can help?

Posted by: Len at August 28, 2006 03:00 AM

Hi Len,
My application could run normally now,thanks.

Qube

Posted by: Qube at August 29, 2006 06:38 AM

Hi All,

I use a USB bluetooth device to connect with the other Comm port bluetooth device.In Server/Client mode,
I set SOCKADDR_BTH as below:
======================
SOCKADDR_BTH SockAddr = {0};
SockAddr.addressFamily = AF_BTH;
SockAddr.port = 2;
======================
They can communicate with each other.But afer about 1 minute,they disconnect for the Socket received the FD_CLOSE.

But if I set SockAddr like this:
======================
SOCKADDR_BTH SockAddr = {0};
SockAddr.addressFamily = AF_BTH;
SockAddr.serviceClassId = GUID_NULL;
SockAddr.port = BT_PORT_ANY;
======================
They cann't connect.

MSDN said:"The port member must be a valid remote port, or zero if the serviceClassId member is specified."
It's so strange that I got two different results.
Could someone tell me the reason?And why they would disconnect after 1 min?

Thanks~

Posted by: Jeff at September 2, 2006 04:34 AM

GUID_NULL isnt a "valid" guid for a service, it's a "no service" guid...

Posted by: Len at September 2, 2006 09:03 PM

Hi all,

Thanks for all your comments. I have a BT USB dongle (Belkin) wich is compatible with the MS BT stack. The code provided by Len works perfect for me and I'm able to send and receive AT commands from my PC to the BT mobile phone without a problem.

Does anyone know if the MS BT stack provides functions to open a SCO connection to send voice over the BT link? Is there any access to the HCI manager?

Thanks much in advance.
Jose

Posted by: Jose at September 8, 2006 11:27 AM

Hello,

I've gleaned a lot from this blog and all the comments. My thanks to everyone.

I ran into an interesting Windows issue in the process. Maybe some of you have seen this as well. It doesn't seem to be documented anywhere. I have create a Bluetooth serial link, but occasionally, the link will just stop working and I have to pair again to get it going. Today I noticed this error in my system event viewer...

"The mutual authentication between the local Bluetooth radio and a device with Bluetooth radio address (00:17:e7:86:39:0a) failed."

There was also a warning that said...

"Windows cannot store Bluetooth link keys on the local transceiver because it cannot determine whether proper security is enabled for the device."

The second message is documented in the Microsoft KB as something that can be "safely ignored". But no mention is made of this other error. I am seeing this with a D-Link DBT-120, but it may be happening with other adapters as well. I know this is a bit off topic from sockets on Bluetooth, but then again, maybe it's not. Has anyone else run into this?

Bob

Posted by: Bob at September 12, 2006 08:41 PM

We are implementing the SyncML Over Obex Over bluetooth. We have developed over GPRS SyncML Server now we are aiming to include the Obex over bluetooth Support.
We will be thankful if someone can give us the idea and guide us regarding this. We are developin that over VS.NET 2003. But we dont have any Bluetooth Api support.

Regards
Gof

Posted by: Gafoor at September 15, 2006 11:40 AM

Look at this:
http://www.btframework.com
It should be usefull for you.

Posted by: Mike Petrichenko at September 28, 2006 12:33 AM

Hi,

I have a VC++ console application that detects bluetooth connections. I need to call these bluetooth funtionalities from a C# application.

So how do i change the VC++ Console application to a DLL?

Secondly how do i consume these bluetooth functions from c# once they are in the form of a DLL?

Pls Help me
Pradsat

Posted by: pradsat at October 3, 2006 08:52 AM

Pradsat,

I assume that you have the source code to the VC++ application? If so, get in touch via email and I'll quote you a price for the work.

Posted by: Len at October 3, 2006 12:08 PM

Hello Everyone

I am working on device discovery using Bluetooth.I tried to compile the code provided by Len in MS Visual Studio 2005.I have downloaded the Platform SDK and also included all the necessary libraries and include files in the linker.But I am getting the following errors:

error C2664: 'WSAAddressToStringW' : cannot convert parameter 4 from 'char [1000]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

error C2440: '=' : cannot convert from 'char [1000]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I am very new to all this.Can anyone help me please?Its urgent...

Posted by: Sree Ramya at January 23, 2007 03:16 PM

Hi

I am using Sony Vaio VGN-BX540BH running Windows XP Pro SP2.I have tried the Bluetooth device discovery code provided by Len.I am getting this error:"Failed to get bluetooth socket! An address incompatible with the requested protocol was used" .

Can someone help me in resolving this error.

Thanks
Ramya

Posted by: Sree Ramya at January 25, 2007 04:46 PM

Hello Allen

I got the same error as you encountered while working on Bluetooth Device Discovery on the code provided by Len.Could you please tell me how did you resolve it?I am using Broadcom USB Dongle.Its urgent.

Thanks
Sree Ramya

Posted by: Sree Ramya at January 25, 2007 05:39 PM

Hello Allen

I got the same error as you encountered while working on Bluetooth Device Discovery on the code provided by Len.Could you please tell me how did you resolve it?I am using Broadcom USB Dongle.Its urgent.

Thanks
Sree Ramya

Posted by: Sree Ramya at January 25, 2007 05:39 PM

Hi Sree Ramya,

I've just reading this post and all its comments (because I'm interested in making a windows bluetooth application, I'm new with this, and it seems to be the unique site with information about it...).
Your error (it's the error code 10047) seem to be due to not supported device or not installed drivers (read in a post posted by: Len at August 13, 2006 03:00 PM).
I hope that it'll be usefull. And sorry my english, it's not very good.

Posted by: Adepa at January 31, 2007 10:00 AM

Hi,

Thank you for your article. Do you know how to retrieve the signal strength of a Bluetooth device through the Microsoft Bluetooth API or Microsoft socks API?

Thanks in advance for your help.

Henry .

Posted by: henry at February 5, 2007 10:10 AM

Henry,

I dont think that's available via those APIs...

Posted by: Len at February 5, 2007 01:12 PM

Hi,

I think I'm going against the flow a bit. My company uses Borland C++ Builder. I don't usually get down into API's since most of my programming requires only serial port communications. I have designed 3 embedded products using Bluetooth devices so I do understand the BT side of things.

I need to find sample code that gets me access to the Platform SDK functions and COMPILEs in my environment. I know what the MSDN says to include, but I am finding many missing definitions for Bluetooth based structures and data types. Does anyone have any idea of the missing .h files I need to ad to make the compile process complete?

Sincerely,

Mike Fontes

Posted by: Mike Fontes at February 14, 2007 01:47 PM

Hi,

Is this a dead thread? I left my message on 2/14 and have not seen any replies or any additional posts.

Is there a better place to get answers to Bluetooth software questions?


Sincerely,

Mike Fontes

Posted by: Mike Fontes at February 26, 2007 12:42 PM

Mike,

It probably just means that nobody has any answers for you.

Sorry.

Posted by: Len at February 26, 2007 02:18 PM

Len,

Does that mean nobody using this site has Borland experience with Bluetooth?

I have been able to find the definitions I needed. I was able to convert the library to COFF when the compiler complained. I have been able to write code that calls the FindFirstRadio function. I have also been able to run your original code.

When the FindFirstRadio is called from mycode or your code I get the NULL return giving an error. The error code returned in both cases is 259. I am not sure if my problem is that Borland isn't working with the MSDN liberary or if the problem is my dongle uses WDComm instead of Microsoft drivers.

My BT dongle is a Belkin that uses the WIDComm driver. I was able to download the driver SDK and the app manual this morning from Broadcom. I have not been able to make any working code yet. As would be expected the Broadcom drivers say they require the VS package.

Has anybody tried these drivers yet? They are very different than the MSDN functions.

Sincerely,

Mike Fontes

Posted by: Mike Fontes at February 26, 2007 07:07 PM

Mike, this code only works with devices that use the MS bluetooth stack. Read the comments in this thread and in the linked threads for more details. Sounds like you'll need to use the sdk that they supply or use a different device...

Posted by: Len at February 28, 2007 02:28 PM

hi all,

i want to transfer file from ppc to pc using socket via bluetooth in asp.net i use vs2003,c#,an i have ipaq ppc to do this pls send me code only in c#

Posted by: smita at March 21, 2007 10:10 AM

does anyone here know if there is any way of checking bluetooth signal strength using c++?

Many thanks,
Kevin

Posted by: kevin at April 5, 2007 06:19 PM

I dont think that functionality is exposed via the sockets interface; I assume that's what you mean.

Posted by: Len at April 6, 2007 10:52 AM

well yeah, ideally I would have liked to do it via the sockets interface. But, are you aware of any other way of checking signal strength? Sorry if im asking daft questions, but this bluetooth programming lingo is pretty new to me.

Many thanks,

Kevin

Posted by: kevin at April 6, 2007 06:30 PM

I would imagine that if you're using a vendor's SDK then that might have a way... I haven't found a way from the XP SP1 Bluetooth API or the sockets integration though. But, to be honest, I haven't really looked that hard as I've never needed to know...

Posted by: Len at April 6, 2007 06:42 PM

Len,

How can I change the bluetooth security level setting via the windows sockets bluetooth implementation?

Thanks,
Kevin

Posted by: kevin at April 9, 2007 05:31 PM

Never needed to, don't think the functionality is exposed, try reading the MSDN docs?

Posted by: Len at April 10, 2007 12:54 PM

len,

I realise that your expertise lies in bluetooth programming for windows xp but I am really stuck with a problem here for my final year university project involving bluetooth programming (using winsock) for windows mobile 5.0. It appears to work in exactly the same way as for windows xp. However, I am trying to use wsalookupservice functionality to retrieve the name, address and service info for surrounding bluetooth devices. I pass in flags LUP_CONTAINERS, LUP_RETURN_ADDR, LUP_RETURN_NAME and LUP_RETURN_TYPE. But, for some reason, error 10022 is being thrown up. If I remove LUP_RETURN_TYPE my code works fine (Except that it doesn't return the service info).

Any insight into this problem would be much appreciated. Even if you could point me in the right direction. Is there a different approach, using winsock to retrieve each devices services structure? Could it be caused by the version of winsock that I am using (2.0).

Many thanks,
Kevin

Posted by: kevin at April 14, 2007 12:31 PM

len,

In reference to my previous comment concerning the querying of devices' available services, I found relevant information on MSDN which is great help.

kevin

Posted by: kevin at April 14, 2007 10:25 PM

Cool. What was your problem?

Posted by: Len at April 15, 2007 07:56 PM

Wow, still answering questions on this three years later? I'm certainly relieved!

I'm working on a project involving Bluetooth communication from a tablet PC running XP Embedded. When I call WSALookupServiceNext, I get what seems to be a valid pointer into lpqsResults, but everything it points to is null (address, name, the "blob", etc). I've got tons of flags being passed to both WSALookupServiceBegin and -Next:

DWORD queryFlags = LUP_RETURN_NAME | LUP_CONTAINERS | LUP_RETURN_ADDR | LUP_RETURN_TYPE | LUP_RETURN_BLOB | LUP_RES_SERVICE;

What do you think might be the problem?
Thanks in advance for any help anyone provides!

Rick Woods
Associate Software Engineer
MICROS, Inc.

Posted by: Richard Woods at April 20, 2007 08:45 PM

Apologies if this question is double-posted...

I'm attempting to use the information generated in the lpqsResults parameter of WSALookupServiceNext, but everything it points to (address, name, the "blob", etc) is null. It's running on a tablet with built-in Bluetooth hardware that's (according to the manufacturer) compatible with Microsoft's Bluetooth stack, and the tablet's OS is XP Embedded.

Thanks in advance for any advice from anyone!

Posted by: Richard Woods at April 20, 2007 09:00 PM

Richard,

I had a similar problem a while back. If I remember rightly I just passed in LUP_CONTAINERS to WSALookupServiceBegin.

status = WSALookupServiceBegin(&querySet,
LUP_CONTAINERS,
&hLookup);

where querySet is of type WSAQUERYSET

Then, in my call to WSALookupServiceNext I passed in the flags that I required.

status = WSALookupServiceNext (hLookup,
LUP_RETURN_NAME | LUP_RETURN_ADDR,
&dwResultSize,
resultSet);

where resultSet is of type PWSAQUERYSET

Posted by: Kevin Brady at April 25, 2007 02:41 PM

Wow, I hadn't realized I triple-posted... It took me a while to figure out I can't see my posts right away. Moving on...

Thanks for the help. It worked. I have only LUP_CONTAINERS passed to the Begin call and LUP_RETURN_ALL passed to the Next call. Now I've got a different problem... Trying to connect() to the device (an Epson TM-P60 printer, for what that's worth) returns 10022, which indicates an invalid parameter. The parameters I'm passing to connect are as follows:

SOCKET comm = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

SOCKADDR_BTH address;
address.addressFamily = AF_BTH;
address.btAddr = addresses[choice];
address.port = 0;
address.serviceClassId = BluetoothPrintTestServiceClass;
returnCode = connect(comm, (struct sockaddr*)&address, sizeof SOCKADDR_BTH);

Where addresses is a vector from which the user has chosen an address to connect to.

Posted by: Richard Woods at April 26, 2007 03:50 PM

Ah, the documentation on connect() shows that they're using this parameter for something completely different -- "The parameter s is a listening socket." So now, I suppose, the question becomes "How in the world do I make it _not_ listening"? I see functions for listen, bind, accept, send, recv, etc. But I don't see any documented way to "unlisten" a socket. Ideas anyone?

Also, I realize that this is a comment on a blog post, and I'd love an actual forum to exist which discusses these things, but when I posted on the MSDN forums my post quickly made it to the third page without being responded to -- does anyone know of a nice place to discuss this topic?

Posted by: Richard Woods at April 27, 2007 04:49 PM

Richard,

No need to create a "non-listening" socket. The SOCKADDR_BTH container you created tells the connect function who you want to connect to. The socket that you create is simply a bluetooth socket. (as you have wrote):

socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

The setup up of a server socket (listening socket) requires to use listen(), bind() and accept(). A client socket simply uses connect(). Look at the Len's examples. They are very useful!!

kevin

Posted by: kevin at April 28, 2007 06:46 PM

Len,

Do you know how I would create a "dummy" client to release a blocking accept() call?

When I stop my server, it is in an Accept() call waiting for a connection. To release it I need some sort of dummy client. Can it be done, just as if I using standard windows sockets?

Have you any other suggestions on how to stop the accept() call?

Many thanks,
Kevin

Posted by: kevin at April 28, 2007 06:50 PM

Just close the socket that's waiting in an accept and the accept will complete with an error - i think.

Posted by: Len at April 29, 2007 11:58 PM

If someone get an unresolved symbol for L2CAP_PROTOCOL_UUID, try to use #include

Posted by: Azuritek at May 3, 2007 03:10 PM

bthdef.h

Posted by: Azuritek at May 3, 2007 03:15 PM

I had success in getting a Bluespoon USB adapter (which uses the toshiba stack) to work with Win XP SP2. I had to modify the bth.inf file that is located in WINDOWS\inf to force it load the microsoft drivers. After doing so, the app ran beautifully. I think this approach will work for most devices (especially if they have an initial listing in the bth.inf file)

Check this guys site for more details... http://sheerboredom.net/modules.php?name=News&file=article&sid=93

Posted by: jenn at June 4, 2007 07:24 PM

Hi,
I'm developing some application for connecting PDA and bluetooth printer. Application is quite simple, it need just to connect with printer(for now) using pairing. I have name, pass key and (MAC) address of BT printer.
OS is windows CE 5.0.
This is code:

CString error;

WORD wVersionRequested = 0x202;
WSADATA m_data;


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

if (s == INVALID_SOCKET) {
error.Format(_T("Socket creation failed, error %d"), WSAGetLastError ());
AfxMessageBox (error);
return;
}

SOCKADDR_BTH sab;
memset (&sab, 0, sizeof(sab));

if (0 != bind (s, (SOCKADDR *) &sab, sizeof(sab))) {
error.Format(_T("Socket bind, error %d"), WSAGetLastError ());
AfxMessageBox (error);
closesocket (s);
return;
}

listen (s, 5);
for ( ; ; ) {

SOCKADDR_BTH sab2;
sab2.addressFamily = AF_BTH;
sab2.btAddr = b; //b is a BT_ADDR variable
sab2.serviceClassId = GUID_NULL;
sab2.port = 4;
int ilen = sizeof(sab2);

sockaddr *pAddr = (sockaddr*)&sab2;

SOCKET s2 = accept (s, pAddr, &ilen);

if (s2 == INVALID_SOCKET) {
error.Format(_T("Socket bind, error %d"), WSAGetLastError ());
AfxMessageBox (error);
break;
}
error.Format(_T("Connection came from %04x%08x to channel %d"),GET_NAP(sab2.btAddr), GET_SAP(sab2.btAddr), sab2.port);
AfxMessageBox (error);
}

closesocket (s);
}

But I get a 10047 (Protocol not supported by address family error) when I use the socket command.
How can I do pairing?

Thanks...

Posted by: Sloba at July 4, 2007 09:48 AM

See the answer here: http://www.lenholgate.com/archives/000104.html

Posted by: Len at July 4, 2007 04:55 PM

Please help me!
I have to make communication via bluetooth from my PC to any other device.

1. Search for a device.
2. Transfer a file

I work in XP SP2.
I've heard that sp2 already have bluetooth drivers, and no need to install something else.
But I do... i install BlueSoleil soft with Broadcomm stack. When I get nothigh with it - I deinstall it.

So neither with BlueSoleil nor without I cannot connet to any device.

BluetoothFindFirstRadio returns "RPC is unavailable".

socet( AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM ) failed with error 10047 "WSAEAFNOSUPPORT"


-----------
Please help!!!
How shall i activate microsoft bluetooth stack?
Thanks.

Posted by: Amor at July 8, 2007 05:57 PM

I'd start by reading all the other comments to this and the other bluetooth posts on this blog.

If your device is supported by the MS bluetooth stack then it should just work. If it requires you to install another driver, etc, then chances are you need a separate SDK from whoever is providing the stack...

Posted by: Len at July 8, 2007 06:36 PM

Hi Len:

This post is about as close as I have come to finding an answer to the question "can two or more bluetooth dongles be placed on a system using the microsoft bluetooth drivers. We can install multiple dongles but we get error code 10 -- device failed to start for the second. We need multiple dongles because we are using them (distributed) for location based services. You seem to be about 100 times more knowledgable than any one else out there. Appreciate any thought you might share. I'm guessing the problem may be with one of the sys files

Posted by: Michael Spring at August 21, 2007 02:36 PM

Hi i am trying to set a BT Service on my desktop PC. I have a Belkin Dongle with windowsstack working. I use windows vista and Visual Studio 2005.

I Got the code as followed:
SOCKET s=socket(AF_BTH,SOCK_STREAM,BTHPROTO_RFCOMM);
SOCKADDR_BTH name;
memset(&name,0,sizeof(name));
name.addressFamily=AF_BTH;
name.btAddr=0;
GUID guidNULL;
memset(&guidNULL,0,sizeof(GUID));
name.serviceClassId=guidNULL;

name.port=BT_PORT_ANY;
sockaddr *pAddr=(sockaddr*)&name;
if(0!=bind(s,pAddr,sizeof(SOCKADDR_BTH)))
{

std::cout closesocket(s);
exit(1);
}

int size = sizeof(SOCKADDR_BTH);
if (0 != getsockname(s, pAddr, &size))
{
std::cout exit(1);
}
if (0 != listen(s, 10))
{
std::cout exit(1);
}
else
{

}
//SET UP SERVICE
WSAQUERYSET service;
memset(&service, 0, sizeof(service));
service.dwSize=sizeof(WSAQUERYSET);
LPTSTR szName = _T("BT Listener");
LPTSTR szComment = _T("BT Listener Comment");
service.lpszServiceInstanceName=szName;
service.lpszComment=szComment;
GUID serviceID = OBEXFileTransferServiceClass_UUID;
service.lpServiceClassId = &serviceID;
service.dwNameSpace = NS_BTH;
service.dwNumberOfCsAddrs = 1;
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))
{
int lastError=WSAGetLastError();
printf("ERROR WSASetService:%i\n", lastError);
}
else
{
std::cout SOCKET s1 = accept(s, 0, 0);
std::cout }
If i execute it i get no error, but the service cannot get discovered by the mobile devices...
Does anyone have an idea why?
Thanks a lot for help...

Posted by: Smilysep at August 22, 2007 07:20 PM

Hi, I'm new in bluetooth programming. I would like to know how to create a L2CAP connection (by using winsock--windows xp sp2 + visual c++ + windows sdk). I'm trying to create socket
SOCKET s = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_L2CAP);
But it's not working, is there anyone can tell me what should i do?? Thanks in advance...

Posted by: blueblur at October 4, 2007 01:37 PM

Blueblur,

'but it's not working' isn't especially helpful. I assume you've read all the stuff on this page and the one linked to it so we're not dealing with an incompatible hardware issue?

Posted by: Len at October 4, 2007 01:42 PM

Hi Len,
Oh.. sorry for my unclear question...
Yes, I have read all the stuff above. I have setup bluetooth dongle with all the steps and it is working prefectly with windows xp. And your example coding, i managed to compile and run.
But I would like to create a connection via L2cap instead of via RFCOMM. So I have change the protocol from BTHPROTO_RFCOMM to BTHPROTO_L2CAP when i'm creating socket. And I obtain the error code WSAEAFNOSUPPORT 10047. I have checked this error code from MSDN's list on error codes, it mean the address family not supported by protocol family.. So I would like to know is it true there is not another method to create a L2CAP connection at windows xp by using windows sdk??
Thanks...

Posted by: blueblur at October 4, 2007 04:37 PM

ops.. sorry, I said wrong error code. it's not 10047, it is WSAEPROTONOSUPPORT 10043 -- Protocol not supported.

Posted by: blueblur at October 4, 2007 05:02 PM

I don't have a machine set up that I can test this on at the moment, will try and do so over the weekend.

Posted by: Len at October 5, 2007 09:27 AM

Having had a play around with this today and having looked at the headers and done a few google searches I've come to the conclusion that it's not supported...

Posted by: Len at October 7, 2007 12:51 PM

Good day dear community!

A lots of my customers ask me about "How do I change the local radio name for MS BT drivers?" Actually this is a big problem. Was.. I have found the way (I am not sure it will work on Vista because requires some additinal privilegies for execute DeviceIOControl. But it works perfect on WinXP machine). So I want to let you know how to do so. I am rally sorry the code below is on Pascal (Delphi) but I usually uses Delphi in my every day development. So, here is the code:

procedure TBFBluetoothRadio.SetNameMicrosoft(Value: WideString);
var
RegKey: string;
CompName: array [0..255] of Char;
CompNameSize: DWORD;
CompNameStr: string;
ACode: DWORD;
Written: DWORD;
NewName: string;
hRadio: THandle;

// Short comment: at present MS does not support more that one dongle
// so I check only 1!!!
function GetInstanceString: string;
var
PnPHandle: HDEVNOTIFY;
GUID: TGUID;
DeviceInfoData: SP_DEVINFO_DATA;
Data: PByte;
DataSize: DWORD;
DataType: DWORD;
Loop: DWORD;

const
BT_GUID: TGUID = '{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}';

begin
Result := '';

GUID := BT_GUID;

PnPHandle := SetupDiGetClassDevs(GUID, nil, 0, DIGCF_PRESENT or DIGCF_PROFILE);

if PnPHandle > Pointer(INVALID_HANDLE_VALUE) then begin
DeviceInfoData.cbSize := SizeOf(SP_DEVINFO_DATA);

Loop := 0;
while SetupDiEnumDeviceInfo(PnPHandle, Loop, DeviceInfoData) do begin
Data := nil;
DataSize := 0;

while not SetupDiGetDeviceRegistryProperty(PnPHandle, DeviceInfoData, SPDRP_HARDWAREID, DataType, Data, DataSize, DataSize) do
if GetLastError = ERROR_INSUFFICIENT_BUFFER then
Data := GetMemory(DataSize)

else
Break;

if Assigned(Data) then
Result := string(PChar(Data)) + #0

else
Result := '';

FreeMemory(Data);

if Pos('MS_BTHBRB', Result) = 0 then begin
Data := nil;
DataSize := 0;

while not SetupDiGetDeviceInstanceId(PnPHandle, DeviceInfoData, PCHar(Data), DataSize, DataSize) do
if GetLastError = ERROR_INSUFFICIENT_BUFFER then
Data := GetMemory(DataSize)

else
Break;

if Assigned(Data) then begin
Result := string(PChar(Data)) + #0;
FreeMemory(Data);
Break;
end;
end;

Result := '';

Inc(Loop);
end;

SetupDiDestroyDeviceInfoList(PnPHandle);
end;
end;

begin
RegKey := GetInstanceString;

if RegKey > '' then begin
SetLength(RegKey, Length(RegKey) - 1);
RegKey := 'SYSTEM\CurrentControlSet\Enum\' + RegKey + '\Device Parameters';

with TRegistry.Create do begin
RootKey := HKEY_LOCAL_MACHINE;

try
if OpenKey(RegKey, False) then
try
CompNameSize := SizeOf(CompName);

if GetComputerName(CompName, CompNameSize) then
CompNameStr := string(CompName)

else
CompNameStr := '';

if (Value = '') or (Value > CompNameStr) then
try
NewName := string(Value) + #0;
WriteBinaryData('Local Name', Pointer(NewName)^, Length(NewName));

except
RaiseWriteName;
end

else
DeleteValue('Local Name');

ACode := 4;

hRadio := GetHandle;

if hRadio > 0 then
try
if not DeviceIoControl(hRadio, $00220FD4, @ACode, 4, nil, 0, Written, nil) then RaiseWriteName;;

finally
CloseHandle(hRadio);
end

else
RaiseWriteName;

finally
CloseKey;
end

else
RaiseWriteName;

finally
Free;
end;
end;

end else
RaiseWriteName;
end;

Short comments:
RaiseWriteName function raises an exception when something goes wrong
GetHandle - returns the radio handle using BluetoothFindxxxxRadio functions

Feel free to send me any questions at mike [@] btframework.com or leave your questions and comments on forum.btframework.com

Thank you!

Posted by: MikePetrichenko at November 3, 2007 09:39 AM

Deepak, the reason it waits is because the accept function can block the call until a connection is present. Please refer to http://msdn2.microsoft.com/en-us/library/ms737526.aspx

Posted by: ting at November 27, 2007 02:20 AM

i want to read data from bluetooth serial port but could not. so, can any one help me

Posted by: asmita at November 27, 2007 03:46 AM

excuse me, im a newbie programmer and i need a code on how to to be able to send files from a cellphone to a pc through bluetooth in vb.net

can anyone post a code here on how to detect a bluetooth device and how to send files to the pc in vb.net?

i would really really appreciate your help!!

Posted by: nahum at December 14, 2007 02:34 PM

excuse me, im a newbie programmer and i need a code on how to to be able to send files from a cellphone to a pc through bluetooth in vb.net

can anyone post a code here on how to detect a bluetooth device and how to send files to the pc in vb.net?

i would really really appreciate your help!!

ps. you can also send it to my email.

Posted by: nahum at December 14, 2007 02:37 PM

I am having trouble with my bluetooth , it will let me send a file from my pc to my mobile phone but when i atempt to recieve a file to my pc from my phone it says An invalid argument was supplied.
Could you help ? Emma

Posted by: Emma at January 3, 2008 12:19 AM

i have to develop an application to get MAC(Media Access Control) address of the mobile which is in bluetooth network in C#. could u please help me? please send me the code to my id i.e jayanthnadig@gmail.com. Thanks...........

Posted by: Jayanth Nadig at January 4, 2008 05:43 AM

Jayanth,

Of course, I have nothing better to do than do your work for you for free...

If you would like me to quote for the work then send me more details of exactly what you require and we can talk about the money.

Posted by: Len at January 4, 2008 09:56 AM

I am developing an HSP profile in winCE 5.0. Can you please explain me hot to do the connection establishment. How can I find the other remote device. Which APIs I have to use for this ? Also how to connect to those devices.. I am new to this area.. plz help me out
Thanks&Regards,
Anil

Posted by: Anil at March 25, 2008 06:14 AM

Well, I guess if you'd actually read any of the stuff on this page you'd have realised that none of it is about WinCE...

Sorry, I've no idea.

Posted by: Len at March 25, 2008 08:39 AM

I am working on some Bluetooth related project and i wanted to ask how to add BluetoothAPIs.h header? Does it have to do anything with SDK? If it does, then kindly let me know the appropriate version and the link from where to download (if possible). I am working in Visual C++ to develop an API for desktop systems.

Thanks in advance!

Posted by: Maria at April 1, 2008 06:51 PM

You need the Platform SDK for Windows XP SP1 or later. Google for Platform SDK and you'll find out how to download it.

Posted by: Len at April 5, 2008 08:34 AM

//#include "stdafx.h"
#include
using namespace std;
#include
#include
#include
#include
#include

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

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


int wmain(int argc, wchar_t** argv)
{

HWND hwndParent=NULL;
BLUETOOTH_DEVICE_INFO* pbtdi=NULL;
BLUETOOTH_DEVICE_SEARCH_PARAMS BluetoothSearchParams;
BLUETOOTH_DEVICE_INFO_STRUCT BluetoothDeviceInfo;

//HBLUETOOTH_DEVICE_FIND hBluetoothDevice;
ZeroMemory(&BluetoothSearchParams, sizeof(BluetoothSearchParams));
ZeroMemory(&BluetoothDeviceInfo, sizeof(BluetoothDeviceInfo));
BluetoothSearchParams.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);
BluetoothSearchParams.fReturnAuthenticated= true;
BluetoothSearchParams.fReturnRemembered = true;
BluetoothSearchParams.fReturnUnknown = true;
BluetoothSearchParams.fReturnConnected = true;
BluetoothSearchParams.fIssueInquiry = true;
BluetoothSearchParams.cTimeoutMultiplier = 15;
BluetoothSearchParams.hRadio = NULL;
BluetoothDeviceInfo.dwSize = sizeof(BluetoothDeviceInfo);
BLUETOOTH_FIND_RADIO_PARAMS* pbtfrp= NULL;
HANDLE* phRadio = NULL;
HBLUETOOTH_RADIO_FIND hFind;

//HANDLE hBluetoothDevice = BluetoothFindFirstRadio(&BluetoothSearchParams, &BluetoothDeviceInfo);
hFind = BluetoothFindFirstRadio(pbtfrp, phRadio);

cout if (hFind != NULL)
{

while (true)
{
cout if (BluetoothFindNextRadio(hFind, phRadio) == false)
{
break;
}

}
}
else
{
cout


}
return 0;
}

I have written this code to enumerate the BT devices but it doesnt work and i always get NULL value from Bluetooth find first device function, also stdafx.h is not recognized by my VS.NET , im working with C++, Can anyone please tell me whats wrong with this code!! also if i do the same for radios i get zero results i,e. no device found.

And whats the difference between functions in SDK for radios, and Devices.

Thanks in advance
Maria

Posted by: at April 25, 2008 07:29 AM

Try checking the value of GetLastError() after the function that fails?

Try reading all the comments on this and the other bluetooth posts here, they clearly state what your system needs to support to be able to work with the winsock functions.

Most probably your devices use a third party bluetooth stack, in which case you need the SDK for that stack rather than using the windows functions.

Posted by: Len at April 25, 2008 09:30 AM

I am using XP Service Pack 2, MS SDK 6.0 is installed and i have integrated it with MS Visual Studio 2005. Doing this from the Start menu: MS Windows SDK >> Visual Studio Registration >> integrate Windows SDK with MS Visual Studio 2005.

I used GetLastError as you suggested and the error i got is : 126 , i have searched about it and i discovered that we get this error when The specified module could not be found. I am not getting it! Does it mean that my SDK is not integrated properly with VS but if that wouldve been the case the libraries and headers that i added would've generated an error too. Do i need to specify some paths of libraries or headers too?? in addition to doing the integration

Thanks in advance
Maria

Posted by: at April 26, 2008 06:11 AM

I searched today and got to know that i can use DEPENDS.EXE to chk for dll dependencies ... i dont know how to use it .. do u have any idea regarding this ...and how to fix this dependency issue??
Maria

Posted by: at April 27, 2008 07:19 PM

Maria,

What is the system that you are building and running the code on? You are building FOR Windows XP SP1 or later are you running ON this platform?

Read the help file that comes with depends.exe.

Posted by: Len at April 28, 2008 08:16 AM

Im working on Windows XP SP2, Dell inspiron 6400 using Visual studio 2005. I have posted the code abv can u kindly run it and check if it works on ur machine.!!

Also if i try to install SDk on Vista the installaation process just haults and doesnt work. I try to do it through the setup folder the x86 versions of SDK setups , the SDKsetup x86 doesnt work as one of the cab files is corrupt.

Thanks,
Maria

Posted by: at April 29, 2008 09:51 AM

Maria,

"I have posted the code abv can u kindly run it and check if it works on ur machine.!!"

Er, no. If you'd like me to send you a quote for consultancy then we can talk about me taking a more active role in debugging your code.

Read the comments on all of the bluetooth related postings on here. Run the demo bluetooth server from here and see if it runs, if it DOES run then your code is broken, if it doesnt run then your hardware isnt suitable. It gives reasonably sensible error messages.

Posted by: Len at April 29, 2008 10:44 AM

Hi everyone,

I have a problem. I want to change the name of my Bluetooth-Device. So i did everything Mike Petrichenko wrote above about changing the local radio name. Now everything works except the DeviceIoControl-Function. Does anyone know how it works with c++? What i do is the following:

I convert the hex-operation-code into an integer (Hex: 00220FD4, Int: 2232276) and my Function is like the following:
DWORD outputBytes = 0;
DWORD written = 0;
DeviceIoControl(handle, code (2232276), NULL, 0, NULL, outputBytes, &written, NULL);

What i get when I call WSAGetLastError(), i get the errocode 6, which means "Invalid Handle".

The handle, i get with the following Function:
handle = SetupDiGetClassDevs(GUID, NULL, 0, DICF_PRESENT | DIGCF_PROFILE); and I check if the handle is invalid and it is not!

Can anyone help me who solved this problem?

Thanks,

Reto

Posted by: Reto Bachmann at May 29, 2008 07:17 AM

can you send me your project code for me

I compile this code
I got an eroor message
uuid.lib(bthguid.obj) : fatal error LNK1103: debugging information corrupt; recompile module
Error executing link.exe.

can you tell me
what's wrong with me
can some one help me
I have see the response ,but I still can troubeshoot it

Posted by: alert at July 6, 2008 02:24 PM

Read the other comments on this page?

Posted by: Len at July 6, 2008 04:18 PM

How can I disable bluetooth service which it is now
and disconnet bluetooth device with PC
how can I do ? Can anyone give me some example

Posted by: alert at July 14, 2008 09:01 AM

the latest platform SDK means vista SDK or xp sdk

Posted by: at September 19, 2008 04:13 AM

Any platform SDK that supports XP SP1, yes.

Posted by: Len at September 19, 2008 08:57 AM

how to detect local bluetooth device, and how can I konw it's state(open/close), I want to develop an application for pc blue tooth with other device, could you give me some samples use C++ or C#, thanks!

Posted by: eric at September 25, 2008 03:31 AM

hy, i want to send a file via BT using the File Transfer Protocol

my program works up to connecting to the mobile device, i can send bytes to the appropriate port, but i have no idea how to use a BT service

Visual C++, Windows Xp

Posted by: cip_u2 at October 17, 2008 08:24 AM

forgot to add: i want to use only Microsoft's Stack

Posted by: cip_u2 at October 17, 2008 12:10 PM

can some one send me the code listing to work with bluetooth devices using visual basic 2005. email address forbesimba@tsamail.co.za

Posted by: forbes at October 22, 2008 01:36 AM

Hi All!
I write client application to perform AT-command on my mobile phone.
I create connect follow:

SOCKADDR_BTH Addr;
memset(&Addr,0,sizeof(Addr));
Addr.addressFamily=AF_BTH;
Addr.btAddr=bDeviceInfo.Address.ullLong;
Addr.port=BT_PORT_ANY;
Addr.serviceClassId=DialupNetworkingServiceClass_UUID;

int rc=connect(s,(sockaddr *)&Addr,sizeof(Addr));

The connect created success. Then, I try to send data via the connect follow:

if(rc==0){
char sb[100]="ATZ\n",rb[100];
int r=0;
do{
Sleep(2000);
r=send(s,sb,strlen(sb),0);
printf("result=%i buffer=%s \n",r,sb);


r=recv(s,rb,100,0);
if(r>0){
r[r]='\0';
printf("result=%i buffer=%s\n",r,rb);
}
}while(r>0);
}

Finally, function recv return the same that i put in function send. Example:

result=4 buffer=ATZ
result=4 buffer=ATZ
result=4 buffer=ATZ
result=4 buffer=ATZ
....


Why?????Thanks

Posted by: progr at January 15, 2009 06:55 AM

I wrote an app that discovers devices and services using MS stack. All works well, but now I'd like to be able to transfer files to my phone LG VX8300. I wrote a winsock code that creates socket, connects to it and writes some string... every operations goes through without any errors. However, I cannot see anything on my phone neither in real time (except authentication prompt) nor browsing it... that is, I dont know where the string goes, where I am supposed to find it? Or it is just discarded somehow. I do know that the phone supports obex push and that's the service I am using... any ideas?

Posted by: Bronsky at January 25, 2009 07:52 PM

I assume you're implementing the obex push protocol and sending the correct data to the socket?

Posted by: Len at January 26, 2009 08:24 AM

Hi Len,

I am developing a C++ API for interacting with robot. For that I want my C++ API to communicate with robot and it should work with Windows as well as MAC PC and on Linux. Can you please guide me in this regard?

I found much stuff which is in Java (e.g. bluecove) but not in C++.

Posted by: Anagha at March 24, 2009 11:21 PM

hi! im trying to compile the sample code. im using xp sp2, i already have the xp sdk but i cannot compile the code it says:
C2065: 'AF_BTH' : undeclared identifier
C2065: 'BTHPROTO_RFCOMM' : undeclared identifier

can you help me? thanks a lot!

:D

Posted by: eimi at May 28, 2009 04:11 AM

pls. disregard my prev. question, i solved it already. however, im having an error while executing the program. Error 10108: "No such service is known. The service cannot be found in the specified name space." i'm using a BT dongle

Posted by: eimi at May 28, 2009 07:49 AM

Read the comments, you need to make sure that you have native XP support for your device.

Posted by: Len at June 1, 2009 10:23 AM

Hi all,

i have a doubt. Can i develop a Bluetooth Server application in C independent of Operating System.
Is there any separate header files are available for this.

the following code i have tried but it is Linux based:
#include
#include
#include
#include
#include

int main(int argc, char **argv)
{
struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
char buf[1024] = { 0 };
int s, client, bytes_read;
socklen_t opt = sizeof(rem_addr);

// allocate socket
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// bind socket to port 1 of the first available
// local bluetooth adapter
loc_addr.rc_family = AF_BLUETOOTH;
loc_addr.rc_bdaddr = *BDADDR_ANY;
loc_addr.rc_channel = (uint8_t) 1;
bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));

// put socket into listening mode
listen(s, 1);

// accept one connection
client = accept(s, (struct sockaddr *)&rem_addr, &opt);

ba2str( &rem_addr.rc_bdaddr, buf );
fprintf(stderr, "accepted connection from %s\n", buf);
memset(buf, 0, sizeof(buf));

// read data from the client
bytes_read = read(client, buf, sizeof(buf));
if( bytes_read > 0 ) {
printf("received [%s]\n", buf);
}

// close connection
close(client);
close(s);
return 0;
}

Can any one help me.
Thanks a lot

Posted by: Vina at June 9, 2009 11:18 AM

Vina,

Think about what you're asking for... Basically someone needs to have created a cross platform library that supports both the operating systems that you need and the devices that you need. At present, at least in the land of windows, it's often hard enough to find drivers that support the 'XP SP1 winsock bluetooth extensions' for devices. Of course there's nothing to stop YOU writing a compatibility layer whilst you're building your app. In fact it's a good idea to do so. Step one would be abstracting away the bluetooth code from the rest of your application; step two is then writing a linux version of the abstraction and then a windows version of the abstraction...

Posted by: Len at June 9, 2009 11:29 AM

Hi Len

I will explain u in detail,
My application is
A Microcontroller with Bluetooth (server) should interact with Mobile which has bluetooth device(client). Its like a Chating Application.

Can u tell me,
I am using Keil C51 compiler.Does it supports bluetooth module. If yes
how to do Bluetooth Server prgramming in Embedded C. If No which compiler I have to use for the Embedded Design.

I have planned to do this by using socket programming.

Please give me your valuable suggestion.


regards
Vina

Posted by: at June 15, 2009 11:22 AM

Vina,

I've no idea.

Posted by: Len at June 15, 2009 11:25 AM

Pass the "BLOB" information.

for more go to

http://msdn.microsoft.com/en-us/library/aa916271.aspx

Posted by: Vivek Pandey at June 18, 2009 11:39 AM

Hi,
Actually i was using a sample code developed based on this one. I am getting error code 259 which indicates ERROR_NO_MORE_ITEMS. Any idea as to what could be the problem?

Posted by: George at September 8, 2009 02:47 PM

It probably means that there are no more items to process... I expect it might help if you told us which part of the code was returning this error code.

Posted by: Len at September 8, 2009 02:54 PM

Thanks for the quick reply. The error is in the BluetoothFindFirstDevice call. Actually an equivalent socket implementation did give me a device after search. So i think i mite be missing something out before the FindFirstDevice call?

Posted by: george at September 9, 2009 05:59 AM

Well, the example code above seems to be only returning 'remembered' devices. I would imagine you have to adjust the search criteria. Remember, the code in the article is just an example, it's not real production quality code!!

Posted by: Len at September 9, 2009 07:55 AM
Post a comment









Remember personal info?




Enter this code in the box below to prove that you're not some kind of automated spam robot...