uwp

问题描述

我正在尝试使用 MFC 平台中的一些现有代码创建一个通过蓝牙连接的应用。

在他们使用的现有代码文件

#include <winsock2.h>
#include <ws2bth.h>
#include <stdio.h>
#include <atlstr.h>
#include <CString>
#include <string>
#include <iostream>
#include <iomanip>
#include <thread>
#include <map>
#include <rpc.h>
#include <bluetoothapis.h>

这些标题。 但是当我取出文件代码并在单独的通用 Windows DLL 类型项目中使用时,它会出现如下错误

Error   C2065   'AUTHENTICATION_REQUIREMENTS': undeclared identifier    
Error   C3861   'BluetoothAuthenticateDeviceEx': identifier not found
Error   C2065   'BLUetoOTH_ADDRESS_STRUCT': undeclared identifier   
Error   C2065   'BLUetoOTH_AUTHENTICATE_RESPONSE': undeclared identifier    
Error   C2065   'BLUetoOTH_AUTHENTICATION_METHOD_NUMERIC_COMPARISON'    
Error   C2065   'BLUetoOTH_DEVICE_INFO': undeclared identifier  
Error   C2065   'BLUetoOTH_DEVICE_INFO': undeclared identifier  
Error   C2065   'BLUetoOTH_DEVICE_INFO_STRUCT': undeclared identifier
Error   C2065   'BLUetoOTH_DEVICE_SEARCH_ParaMS': undeclared identifier 
Error   C2065   'BTHPROTO_RFCOMM': undeclared identifier    
Error   C2065   'BT_PORT_ANY': undeclared identifier

即使包含 标头,它也不会显示错误。在 Visual Studio 中通过 ctrl+left_mouse 单击可遍历引用(BLUetoOTH_DEVICE_INFO、BLUetoOTH_DEVICE_INFO_STRUCT 等)。但是代码没有编译。

我不太明白为什么。 任何帮助将非常感激。 提前致谢。

解决方法

您可以在bluetoothapis.h上方按F12查看文档,您会看到开头有一个#if语句#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)它表示头文件可用于桌面 Win32 应用程序(但不能用于存储应用程序)。通用 Windows DLL 项目不是 Win32 应用程序,因此,无法在项目中使用 bluetoothapis.h 标头。