none
Bluetooth programming

    Question

  • Hey, I have been working on a bluetooth program in c++ that will find devices and display them and send files to them. But I cant get it to work. I have tryed to use the Bluetooth Api and winsock. But no matter how I choose to look at it, will it not work. Under are some codes and links I have been throw.. My question is, If someone could make me a sampel of code that work. Would I be more than HAPPY!

    Hey, I was wondering if I could get some help with a project. I am trying to make program that find the bluetooth devices in range and show them to me. But with no luck. I need some serious help with this. If some one could give me apush in the right direction or a code sampel or anything would I be more then happy:


    Some codes I have been thro:

    [CODE]#include <iostream>
    #include <windows.h>
    #include <bthsdpdef.h>
    #include <BluetoothAPIs.h>

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

    using namespace std;


    // for og finne blåtannenheten min og enheter
    void min_bluetooth()
    {
      DWORD BluetoothAuthenticateDevice(
      HWND hwndParent,
      HANDLE hRadio,
      BLUETOOTH_DEVICE_INFO* pbtdi,
      PWCHAR pszPasskey,
      ULONG ulPasskeyLength
    );
       
    }

    int main ()
    {
        //velkommen
        cout << "Start programmet..." <<endl;
        Sleep(1000);

        //Blåtann starter
        min_bluetooth();

    }[/CODE]

    [CODE]// 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;
    }
    [/CODE]

    [code]#define WIN32_LEAN_AND_MEAN

    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <winsock2.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <BluetoothAPIs.h>
    #include <BT_Finder.h>

    #pragma comment ( lib, "wsock32.lib");
    #pragma comment ( lib, "Ws2.lib");

    using namespace std;

    int main ( int argc, char *argv[] )

    {
        // Bare en liten velkomshilsen
        cout << "starter programmet..." <<endl;
        Sleep(1000);

        // Her starter blåtann
       
       
        CBT_Finder::CBT_Finder(void)
    {
    }

    CBT_Finder::~CBT_Finder(void)
    {
    }

    void CBT_Finder::QueryDevices()
    {
    BLUETOOTH_FIND_RADIO_PARAMS RadioParam;
    RadioParam.dwSize = sizeof(BLUETOOTH_FIND_RADIO_PARAMS);

    BLUETOOTH_FIND_RADIO_PARAMS* FindParam;

    HANDLE* hRadio;
    returnParam = BluetoothFindFirstRadio(&RadioParam, hRadio);


    BOOL MoreDevices;
    do
    {
     Radios.push_back(hRadio);


    MoreDevices = BluetoothFindNextRadio(returnParam,hRadio);

    returnParam
    }while (MoreDevices == TRUE);

    BluetoothFindRadioClose(FindParam);

    for(std::list <HANDLE*>::iterator i = Radios.begin(); i != Radios.end(); i++ )
    {
     BLUETOOTH_DEVICE_INFO RadioData;
     BluetoothGetDeviceInfo(*i,&RadioData);
     printf("%s",RadioData->szName);
    }




    }
    [/code]

    [CODE]
    #pragma once
    #include "windows.h"
    #include "BluetoothAPIs.h"
    #include <list>

    class CBT_Finder
    {
    public:
    CBT_Finder(void);
    ~CBT_Finder(void);
    void QueryDevices();
    std::list <HANDLE*> Radios;

    };

    [/CODE]

    Some links:

    [CODE]
    links:
    http://msdn2.microsoft.com/en-gb/library/aa362942.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362941.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362770.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362941.aspx
    http://msdn2.microsoft.com/en-gb/library/ms741679.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362913.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362914.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362916.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362915.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362900.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362920.aspx
    http://msdn2.microsoft.com/en-gb/library/aa363059.aspx
    http://msdn2.microsoft.com/en-us/library/aa363057.aspx
    http://msdn2.microsoft.com/en-us/library/aa362899.aspx
    http://support.microsoft.com/default.aspx?kbid=841803
    http://www.lenholgate.com/archives/000102.html
    http://msdn2.microsoft.com/en-gb/library/aa362930.aspx
    http://msdn2.microsoft.com/en-gb/library/aa362924.aspx
    [/CODE]

    Friday, February 16, 2007 8:34 AM

All replies

  • Hey, I have been working on a bluetooth program in c++ that will find devices and display them and send files to them. But I cant get it to work. I have tryed to use the Bluetooth Api and winsock. But no matter how I choose to look at it, will it not work. Under are some codes and links I have been throw.. My question is, If someone could make me a sampel of code that work. Would I be more than HAPPY!

    You have to explain what doesn't work. Did you try debugging it?

    Friday, February 16, 2007 1:59 PM
  • Yes, when I try to build this kode:


    #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;
    }



    I get this log:


    ------ Rebuild All started: Project: fwefwef, Configuration: Debug Win32 ------
    Deleting intermediate and output files for project 'fwefwef', configuration 'Debug|Win32'
    Compiling...
    main.cpp
    c:\documents and settings\administrator\mine dokumenter\visual studio 2005\projects\fwefwef\fwefwef\main.cpp(134) : 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
    c:\documents and settings\administrator\mine dokumenter\visual studio 2005\projects\fwefwef\fwefwef\main.cpp(141) : 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
    c:\documents and settings\administrator\mine dokumenter\visual studio 2005\projects\fwefwef\fwefwef\main.cpp(149) : 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
    c:\documents and settings\administrator\mine dokumenter\visual studio 2005\projects\fwefwef\fwefwef\main.cpp(182) : 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
    c:\documents and settings\administrator\mine dokumenter\visual studio 2005\projects\fwefwef\fwefwef\main.cpp(189) : 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
    Build log was saved at "file://c:\Documents and Settings\Administrator\Mine dokumenter\Visual Studio 2005\Projects\fwefwef\fwefwef\Debug\BuildLog.htm"
    fwefwef - 5 error(s), 0 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


    And I am not right sure if that code will work. I am trying ot make a aplication that will find some devices then send them random files frome a directory I have.

    Thanks for all help!


    Friday, February 16, 2007 2:21 PM
  •  

    I have been working on the same idea for the last 3 weeks using basic winsock and building my own OBEX API to implement a simple OPP client.  So far I have managed to identify devices and send Vcard (.vcf)/ Vcal (.vcs)/ and JEG(.jpg) files to a Nokia phone.  The software is developed for a generic WindowsXP BT stack.  Send me an email if you want a copy of what I have so far.  This is a work in progress.

    Sunday, April 15, 2007 11:54 AM
  • Hi,

     

    I think the biggest problem you are having with this code, is that by the looks of it the code example you are trying to compile appears to have been designed for the desktop bluetooth APIs. I come to this conclusion because the compiler errors you are having are due to Unicode vs ANSI issues. The APIS available on the Pocket PC are only available in Unicode form and the code example you provided is full of ANSI strings. Likewise if these were corrected I imagine the linker would start giving you trouble due to use of unavailable function calls.

     

    The Bluetooth APIs exposed on a Windows CE / Windows Mobile device has a slightly different design. With some features not exposed, others exposed differently and other new APIs added.

     

    If you have the Windows Mobile 2005 Pocket PC SDK installed have a look at one of the examples included with it. It is called btsearch and is desrcibed at http://msdn2.microsoft.com/en-us/library/ms880582.aspx

     

    With a default install you will be able to find this example on you PC under C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Samples\CPP\Win32\Bluetooth\btsearch

     

    This example shows how to use the Microsoft bluetooth stack on a device to perform a device discovery and populates a listbox with the names of detected bluetooth devices.

     

    This example should give you a point in the right direction with respect to getting a bluetooth example up and running. After you have got this example working on your device you can simply extend it as you need to perform your other tasks.

     

    There are also a couple of othe SDK examples which may be of use to you, including bthchat - http://msdn2.microsoft.com/en-us/library/ms880620.aspx

     

    The other thing to be aware of (especially on Windows Mobile powered devices) is that some OEMs have choosen not to use the Microsoft bluetooth stack. This means these examples will not operate on those devices.

     

    Of the devices which don't use the Microsoft bluetooth stack the large majority have chosen to go with a stack provided by Widcom. Widcom provide their own SDK for their bluetooth stack and it includes a number of example applications designed to demonstrate it's use. When I started development you had to purchase this SDK for about $1000 USD, however it has now been made a free download from their website. It can be located at http://www.broadcom.com/products/bluetooth_sdk.php (you are looking for the BTW-CE Software Development Kit for Windows Mobile Development Platform SDK).

     

    Hope this helps,

    Christopher Fairbairn

     

    Saturday, April 21, 2007 11:12 AM

  • Hey! BluePain i am having the same problems.... if u have managed to do this can u please mail me the code on tranceshapes@gmail.com or paste it here!!

    I hope u read it since this thread is very old Sad ... and u havn't mentioned ur email ID so cant even mail u!
    Sunday, March 30, 2008 6:13 PM
  • Dear Mark,

     

    Could you please forward me a copy of your code which works on a Windows XP BT stack? I am looking for some sample code to see how to write a Bluetooth client-server application using WinSock C++ api. You can send me the email directly instead of posting in the forum because I may not check the forum frequently. Thanks a lot!

     

    Zhiheng Mao

    zmao@qualcomm.com

    Friday, September 26, 2008 10:21 PM
  • Zhiheng Mao ,When you are not checking the forum frequently then how you expect that someone will answer your question by reading this message anyway will suggest you to read Following Link.

    Bluetooth code

    Thanx
    Monday, September 29, 2008 6:06 AM
  • I am Looking help for Bluetooth application development for windows embedded compact 7

    Please do me favour 

     

    Thanks Bipul Pandey

    Friday, January 6, 2017 6:23 AM