Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bluetooth Programming

273 views
Skip to first unread message

Deepika

unread,
Apr 14, 2009, 8:37:01 AM4/14/09
to
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?

Doug Harrison [MVP]

unread,
Apr 14, 2009, 8:56:32 AM4/14/09
to
On Tue, 14 Apr 2009 05:37:01 -0700, Deepika
<Dee...@discussions.microsoft.com> 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

David Lowndes

unread,
Apr 14, 2009, 9:01:27 AM4/14/09
to
> 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

unread,
Apr 15, 2009, 9:01:02 AM4/15/09
to
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

unread,
Apr 15, 2009, 10:44:42 AM4/15/09
to
>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

unread,
Apr 16, 2009, 3:19:05 AM4/16/09
to
>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

unread,
Apr 17, 2009, 3:19:07 AM4/17/09
to
>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

Pavel A.

unread,
Apr 17, 2009, 4:47:41 PM4/17/09
to
"David Lowndes" <Dav...@example.invalid> wrote in message
news:r8bgu4t9aokbue7sp...@4ax.com...

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

Ben Voigt [C++ MVP]

unread,
Apr 20, 2009, 1:14:18 PM4/20/09
to

"David Lowndes" <Dav...@example.invalid> wrote in message
news:r8bgu4t9aokbue7sp...@4ax.com...

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

0 new messages