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?
> 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
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
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.
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
What do you mean by that?
Dave
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
"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