Bluetooth Programming

Discussion in 'Microsoft VC .NET' started by Deepika, Apr 14, 2009.

  1. Deepika

    Deepika Guest

    Hi
    I am trying to do bluetooth programming on Microsoft Visual C++ 6.0.
    I am using basic functions like WSALookupServiceBegin().
    i wrote the code like this
    WSAQUERYSET wsaq;
    wsaq.dwNameSpace = NS_BTH;

    The problem is, the compiler is not recognising NS_BTH and giving compile
    time error.
    I included the following sets of headers and lib

    #include <winsock>
    #include <winsock2>
    #include <bthdef>
    #include <BluetoothAPIs.h>
    #include <Ws2bth.h>
    #pragma comment(lib, "ws2_32.lib")

    The same goes with socket creation.
    Even if i am trying to create socket using the below code

    SOCKET client_socket = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM);

    following error are coming up

    error C2065: 'NS_BTH' : undeclared identifier
    error C2065: 'AF_BT' : undeclared identifier
    error C2065: 'BTHPROTO_RFCOMM' : undeclared identifier

    i am not able to understand what else needs to be included.
    Is it because of Microsoft stack or some SDK is required?
     
    Deepika, Apr 14, 2009
    #1
    1. Advertisements

  2. On Tue, 14 Apr 2009 05:37:01 -0700, Deepika
    <> wrote:

    > Hi
    > I am trying to do bluetooth programming on Microsoft Visual C++ 6.0.
    > I am using basic functions like WSALookupServiceBegin().
    > i wrote the code like this
    > WSAQUERYSET wsaq;
    > wsaq.dwNameSpace = NS_BTH;
    >
    > The problem is, the compiler is not recognising NS_BTH and giving compile
    > time error.
    >I included the following sets of headers and lib
    >
    > #include <winsock>
    > #include <winsock2>
    > #include <bthdef>


    I guess your real code has the .h suffix on those header names?

    > #include <BluetoothAPIs.h>
    > #include <Ws2bth.h>
    > #pragma comment(lib, "ws2_32.lib")
    >
    >The same goes with socket creation.
    > Even if i am trying to create socket using the below code
    >
    > SOCKET client_socket = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM);
    >
    > following error are coming up
    >
    > error C2065: 'NS_BTH' : undeclared identifier
    > error C2065: 'AF_BT' : undeclared identifier
    > error C2065: 'BTHPROTO_RFCOMM' : undeclared identifier
    >
    > i am not able to understand what else needs to be included.
    >Is it because of Microsoft stack or some SDK is required?


    According to this documentation, NS_BTH is declared in <winsock2.h>. If
    your copy of that header does not contain it, you will need to update your
    Platform SDK. If it does contain it, you will need to determine the
    conditional compilation statement that is making it unavailable.

    BTW, always #include <windows.h> first thing. There once was a really nifty
    bug in <winsock2.h> that caused that header to change the struct packing
    when it #included <windows.h> for you, and some headers aren't even
    thoughtful enough to #include <windows.h> for you.

    --
    Doug Harrison
    Visual C++ MVP
     
    Doug Harrison [MVP], Apr 14, 2009
    #2
    1. Advertisements

  3. > The problem is, the compiler is not recognising NS_BTH and giving compile
    > time error.


    Looking at the MSDN documentation for that flag it says "The Bluetooth
    namespace. This namespace identifier is supported on Windows Vista and
    later." - which implies that you probably need a recent SDK
    installation to have an up to date header definition, and you'll also
    need to define a preprocessor symbol to enable the definition - see
    "Using the Windows Headers" on MSDN. Search your header files for that
    definition to see if you have it, and if you do what #if block it's
    contained within to know what preprocessor symbol needs defining.

    Dave
     
    David Lowndes, Apr 14, 2009
    #3
  4. Deepika

    Deepika Guest

    Thanks for the suggestion.
    Winsock2.h is not updated for which i will have to dowload latest PSDK.

    Now i have another problem.

    Today i tried using BluetoothFindFirstDevice() and
    BLUETOOTH_DEVICE_SEARCH_PARAMS. these functions are declared in
    Bluetoothapis.h and this file i have checked is linked properly and is also
    having the defintions for above but still i am having compilation error
    saying "undeclared identifier"
    Following is the code
    #include "BluetoothAPIs.h"
    #include <windows.h>
    #include <Ws2bth.h>
    #include "stdafx.h"
    #include <conio.h>

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

    int main(int argc, char* argv[])
    {
    BLUETOOTH_DEVICE_SEARCH_PARAMS BluetoothSearchParams;
    BLUETOOTH_DEVICE_INFO 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);

    hBluetoothDevice = BluetoothFindFirstDevice(&BluetoothSearchParams,
    &BluetoothDeviceInfo);
    }

    Any idea as to why this problem could be coming.
    Is there anything related to the header file bein c file or c++ file or PSDK
    is again the problem?
    I am not sure of the reason.
    Please guide me.

    "David Lowndes" wrote:

    > > The problem is, the compiler is not recognising NS_BTH and giving compile
    > > time error.

    >
    > Looking at the MSDN documentation for that flag it says "The Bluetooth
    > namespace. This namespace identifier is supported on Windows Vista and
    > later." - which implies that you probably need a recent SDK
    > installation to have an up to date header definition, and you'll also
    > need to define a preprocessor symbol to enable the definition - see
    > "Using the Windows Headers" on MSDN. Search your header files for that
    > definition to see if you have it, and if you do what #if block it's
    > contained within to know what preprocessor symbol needs defining.
    >
    > Dave
    >
     
    Deepika, Apr 15, 2009
    #4
  5. >Today i tried using BluetoothFindFirstDevice() and
    >BLUETOOTH_DEVICE_SEARCH_PARAMS. these functions are declared in
    >Bluetoothapis.h
    >...


    Are they defined within some conditional block? i.e. you need a
    specific preprocessor symbol value defined for them to be available in
    your project.

    Dave
     
    David Lowndes, Apr 15, 2009
    #5
  6. Deepika

    Deepika Guest

    No, they are not defined in some conditional block.
    i have already checked that.
    The following condition is present
    #ifdef __cplusplus
    extern "C" {
    #endif

    What i understood that it is c header filewhich is not workin properly in
    the C++ environment?
    Any idea how to solve it?
    "David Lowndes" wrote:

    > >Today i tried using BluetoothFindFirstDevice() and
    > >BLUETOOTH_DEVICE_SEARCH_PARAMS. these functions are declared in
    > >Bluetoothapis.h
    > >...

    >
    > Are they defined within some conditional block? i.e. you need a
    > specific preprocessor symbol value defined for them to be available in
    > your project.
    >
    > Dave
    >
     
    Deepika, Apr 16, 2009
    #6
  7. >What i understood that it is c header filewhich is not workin properly in
    >the C++ environment?


    What do you mean by that?

    Dave
     
    David Lowndes, Apr 16, 2009
    #7
  8. Deepika

    Deepika Guest

    Actually i faced a similar problem before.
    the header file was a c header file and that implementation file was a cpp
    file.
    The definitions of certain functions defined in the header file were not
    getting recognized the cpp file although i had alreday included that header.
    The problem was solved by changing the project settings -> C/C++ Tab ->
    Precompiled headers -> Not using precompiled heeaders

    This option i read differenctiates the c and c++ header files and builds them.
    The same problem i was anticipating here also.
    But now my blutooth program is building successfully.
    Thanks a lot for all the help

    "David Lowndes" wrote:

    > >What i understood that it is c header filewhich is not workin properly in
    > >the C++ environment?

    >
    > What do you mean by that?
    >
    > Dave
    >
     
    Deepika, Apr 17, 2009
    #8
  9. >Actually i faced a similar problem before.
    >the header file was a c header file and that implementation file was a cpp
    >file.
    >The definitions of certain functions defined in the header file were not
    >getting recognized the cpp file although i had alreday included that header.
    >The problem was solved by changing the project settings -> C/C++ Tab ->
    >Precompiled headers -> Not using precompiled heeaders


    I'm glad things are working ok now, but your diagnosis of the issue is
    wrong - precompiled headers is nothing to do with C headers and C++
    sources.

    Dave
     
    David Lowndes, Apr 17, 2009
    #9
  10. Deepika

    Pavel A. Guest

    "David Lowndes" <> wrote in message
    news:...
    >>Actually i faced a similar problem before.
    >>the header file was a c header file and that implementation file was a cpp
    >>file.
    >>The definitions of certain functions defined in the header file were not
    >>getting recognized the cpp file although i had alreday included that
    >>header.
    >>The problem was solved by changing the project settings -> C/C++ Tab ->
    >>Precompiled headers -> Not using precompiled heeaders

    >
    > I'm glad things are working ok now, but your diagnosis of the issue is
    > wrong - precompiled headers is nothing to do with C headers and C++
    > sources.
    >
    > Dave


    Precompiled headers just don't seem to work automatically
    in a new project, VC won't do the right thing for them,
    so for small projects it's better to disable precomp headers and skip
    all these troubles.

    regards,
    --pa
     
    Pavel A., Apr 17, 2009
    #10
  11. "David Lowndes" <> wrote in message
    news:...
    >>Actually i faced a similar problem before.
    >>the header file was a c header file and that implementation file was a cpp
    >>file.
    >>The definitions of certain functions defined in the header file were not
    >>getting recognized the cpp file although i had alreday included that
    >>header.
    >>The problem was solved by changing the project settings -> C/C++ Tab ->
    >>Precompiled headers -> Not using precompiled heeaders

    >
    > I'm glad things are working ok now, but your diagnosis of the issue is
    > wrong - precompiled headers is nothing to do with C headers and C++
    > sources.


    Well... you can't share a precompiled header between C and C++ compile
    units. At least not if you want __cplusplus to be defined correctly.

    >
    > Dave
     
    Ben Voigt [C++ MVP], Apr 20, 2009
    #11
  12. Deepika

    gswarnal

    Joined:
    Feb 22, 2010
    Messages:
    1
    Likes Received:
    0
    hello please any body can send how to transfer a file between to blutooth enabled devices in windows xp environment in c/c++ programming my emial id is
     
    gswarnal, Feb 22, 2010
    #12
  13. Deepika

    satyaswarup

    Joined:
    Feb 28, 2011
    Messages:
    1
    Likes Received:
    0
    #include "Bluetoothapis.h"
    #include <windows.h>
    #include <Ws2bth.h>
    #include "stdafx.h"
    #include <conio.h>


    #pragma comment(lib, "irprops.lib")
    #pragma comment(lib, "ws2_32.lib")
    #pragma comment(lib, "Bthprops.lib")
    int _tmain(int argc, _TCHAR* argv[])
    {
    BLUETOOTH_DEVICE_SEARCH_PARAMS BluetoothSearchParams ;


    return 0;
    }

    error C2065: 'BLUETOOTH_DEVICE_SEARCH_PARAMS' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'BluetoothSearchParams'
    error C2065: 'BluetoothSearchParams' : undeclared identifier

    i am getting this ,errors can some one help me out??
     
    satyaswarup, Feb 28, 2011
    #13
  14. Deepika

    ethanhunt3055

    Joined:
    May 14, 2011
    Messages:
    1
    Likes Received:
    0
    Can I use this code in my mobile to change the speed.
     
    ethanhunt3055, May 14, 2011
    #14
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cmartin64x

    Bluetooth API calls (not using Sockets)

    cmartin64x, Feb 1, 2005, in forum: Microsoft VC .NET
    Replies:
    1
    Views:
    2,177
    Antti Keskinen
    Feb 2, 2005
  2. funitsu

    Bluetooth api in Dll (Class Library) - problem

    funitsu, Feb 10, 2005, in forum: Microsoft VC .NET
    Replies:
    0
    Views:
    520
    funitsu
    Feb 10, 2005
  3. Nathan Young

    Bluetooth and COM port emulation

    Nathan Young, Aug 30, 2005, in forum: Microsoft VC .NET
    Replies:
    1
    Views:
    374
    William DePalo [MVP VC++]
    Aug 30, 2005
  4. Boki

    Which one is the Bluetooth DLL?

    Boki, May 6, 2006, in forum: Microsoft VC .NET
    Replies:
    4
    Views:
    228
    Guest
    May 8, 2006
  5. Z.K.

    Bluetooth programming ?

    Z.K., Mar 4, 2008, in forum: Microsoft VC .NET
    Replies:
    1
    Views:
    883
    Ben Voigt [C++ MVP]
    Mar 5, 2008
Loading...

Share This Page