PC Review


Reply
Thread Tools Rate Thread

Bluetooth Programming

 
 
Deepika
Guest
Posts: n/a
 
      14th Apr 2009
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?

 
Reply With Quote
 
 
 
 
Doug Harrison [MVP]
Guest
Posts: n/a
 
      14th Apr 2009
On Tue, 14 Apr 2009 05:37:01 -0700, Deepika
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
David Lowndes
Guest
Posts: n/a
 
      14th Apr 2009
> 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
 
Reply With Quote
 
Deepika
Guest
Posts: n/a
 
      15th Apr 2009
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
>

 
Reply With Quote
 
David Lowndes
Guest
Posts: n/a
 
      15th Apr 2009
>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
 
Reply With Quote
 
Deepika
Guest
Posts: n/a
 
      16th Apr 2009
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
>

 
Reply With Quote
 
David Lowndes
Guest
Posts: n/a
 
      16th Apr 2009
>What i understood that it is c header filewhich is not workin properly in
>the C++ environment?


What do you mean by that?

Dave
 
Reply With Quote
 
Deepika
Guest
Posts: n/a
 
      17th Apr 2009
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
>

 
Reply With Quote
 
David Lowndes
Guest
Posts: n/a
 
      17th Apr 2009
>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
 
Reply With Quote
 
Pavel A.
Guest
Posts: n/a
 
      17th Apr 2009
"David Lowndes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>>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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SP2 bluetooth KILLS MY WORKING sitecom bluetooth software =?Utf-8?B?Um9uIFZhcm8=?= Windows XP Help 0 30th Sep 2004 12:31 AM
Bluetooth - Connecting Remote XP via USB Bluetooth aviad Windows XP Networking 1 21st Mar 2004 05:21 PM
Logitech Optical Desktop MX for Bluetooth.... AFTER Microsoft Desktop for Bluetooth Christopher G. Windows XP Help 1 13th Jan 2004 04:24 AM
bluetooth help "My bluetooth places" missing Scott Seidman Windows XP Help 2 3rd Dec 2003 05:06 PM
MS Bluetooth mouse with non MS bluetooth adaptor Peter Parker Windows XP General 0 25th Sep 2003 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:19 PM.