Bluetooth connection sample

This sample demonstrates how to make a Bluetooth connection over RFCOMM using Winsock version 2.2.

C++ (33.8 KB)
 
 
 
 
 
2.7 Star
(19)
40,697 times
Add to favorites
10/17/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Unable to run Sample on Windows 10
    1 Posts | Last post July 11, 2019
    • Using: Visual Studio Community 2019
      Windows 10 on x64 Processor
      
      When I compile the code there is no error, but when i click on Run without debugging, it just displays a blank Command Line Window.
      What is missing from my side ?
      
      
      'bthcxn.exe' (Win32): Loaded 'D:\VSProjects\BluetoothConnectionSample\Debug\bthcxn.exe'. Symbols loaded.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. 
      The thread 0x7150 has exited with code 0 (0x0).
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mswsock.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wshbth.dll'. 
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. 
      
      // Then I have to forcefully exit the Command Line Window.
      
      The thread 0x7ebc has exited with code 0 (0x0).
      The thread 0x3be4 has exited with code 0 (0x0).
      The program '[19724] bthcxn.exe' has exited with code 0 (0x0).
      
  • Error| Cannot find or open the PDB file
    2 Posts | Last post April 29, 2019
    • Hello.
         I have tried building and running this project in Visual Studio 2015. Build is success. But when running it shows following errors.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\apphelp.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sysfer.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
      'bthcxn.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
      How can i resolve this? And what will be the problem?
    • hey,brother.i just know this problem that your computer ` s bluetooth is not ready
  • WSAGetLastError = [10047]
    1 Posts | Last post January 31, 2018
    • After I ran the code I got an error value as to the one above of 10047. I know what it means but I don't know how to fix it. Also this error is from just running the code that was provided with out editing it.
  • 555-555-0199@example.com
    1 Posts | Last post October 13, 2017
    • 555-555-0199@example.com
  • error lpstr to wchar_t
    1 Posts | Last post September 26, 2016
    • Hello, thank you for this useful code ! I have a question though regarding it. I tried to include this in my code where I use Multi byte characters, thus I get an error : "cannot convert from lpstr to wchar_t"  for the line :
      
      if ((pWSAQuerySet->lpszServiceInstanceName != NULL) &&
      						(CXN_SUCCESS == _wcsicmp_l(pWSAQuerySet->lpszServiceInstanceName, pszRemoteName))) {
      
      How can I overcome this? I tried to google it but I get very confused. I wouldnt like to change to Unicode. Thank you very much !
  • BLE communication
    1 Posts | Last post July 13, 2016
    • Hi;
      May I use the socket for BLE communication with beacons? 
      As far as I can see only RFCOMM is implemented?
      What about Bluetooth API? can I use it for BLE communication?
      
      Regards
      
  • Why Can not accept device request?
    1 Posts | Last post May 05, 2016
    • win7 64bit
      I can see the paired device property,which shows "connected"  (the value of last connection time ) in bluetooth tabpage.
      but program is still blocked at " ClientSocket = accept(LocalSocket, NULL, NULL) "
      
  • This is just great [sic]
    1 Posts | Last post August 05, 2015
    • I don't want my Bluetooth devices discovered, listened in on and information transferred. I am not part of an organization, just me trying to run Windows 10, and with a non-Windows phone where my call history shows an outbound call to my Voice Mail PIN after I call it, and after I receive one. Receive it, bye the way, hours or even days later. This is progress?
      
      I am using my son's computer now.
  • IDE Version
    3 Posts | Last post March 04, 2015
    • Why does this sample require Microsoft Visual Studio Ultimate 2012 and not compile in Microsoft Visual Studio Express 2012 for Windows 8?
      
      Does that mean that any program developed (e.g. C# based) to make a Bluetooth connection over RFCOMM using Winsock version 2.2 requires Microsoft Visual Studio Ultimate 2012?
      Sinclair (OBDKey)
      
    • Description is wrong. I've successfully build it with Visual Studio Express 2013 (with Windows SDK for Windows 8.1 installed) and run on Windows 7 SP1 64-bit.
      
      Notes:
      - When I opened solution in IDE it asked me to convert/upgrade deprecated project and I confirmed.
      - I didn't full test because I have only one bluetooth dongle. I've just made sure that it started in server mode without any runtime errors and reached listening cycle.
      
    • As Artem stated, the description is wrong (for both the OS and compiler requirements).  I downloaded the sample onto two separate PCs, both running Windows 7. One had VS2010 installed, the other I just downloaded and installed VS2013 Community on. The sample built and ran no problem on the VS2013 PC but of course I had nothing to connect to it yet. VS2010 wouldn't open the sample solution file, so I created a new Console project and added the sample cpp and rc files. It compiled but had unresolved externals.  I added ws2_32.lib to the linker input list and then it built and ran fine. After figuring out how the sample program command line works, I got it all working - the client PC connects to the server PC and sends it a string of text, which the server PC receives and displays, then they both terminate.  Nothing fancy, and not very user-friendly, but it proves the concept and gives you a starting point to work with. And it builds and runs on Windows 7, and you don't need anything later than VS2010.
  • Error 10060
    2 Posts | Last post September 27, 2014
    • In my case I could compile (32 bits) and run using VS Express 2012 in Windows 7 64bits. I tried to connect two laptops with bluetooth and got error 10060.
      
      I checked the bluetooth address resolved from the machine name and it is correct.
      
      I paired both notebooks and tried again without success, always get 10060 error.
      
      Any ideas?
    • Solved it! It was an outdated driver problem.
1 - 10 of 13 Items