Bluetooth Programming


D

Deepika

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?
 
Ad

Advertisements

D

Doug Harrison [MVP]

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.
 
D

David Lowndes

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
 
D

Deepika

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.
 
D

David Lowndes

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
 
D

Deepika

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?
 
Ad

Advertisements

D

Deepika

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
 
D

David Lowndes

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
 
P

Pavel A.

David Lowndes said:
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
 
B

Ben Voigt [C++ MVP]

David Lowndes said:
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.
 
Ad

Advertisements

Joined
Feb 22, 2010
Messages
1
Reaction score
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 (e-mail address removed)
 
Joined
Feb 28, 2011
Messages
1
Reaction score
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??
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top