简体   繁体   English

如何编译具有“ wlanapi.h”和“ windows.h”依赖项的C ++代码

[英]How To Compile C++ Code that has a 'wlanapi.h' and 'windows.h' dependency

I am modifying an open source code that scans for Wireless signals in the vicinity. 我正在修改一个开源代码,该代码可扫描附近的无线信号。 The program code goes like this: 程序代码如下:

#pragma comment(lib, "wlanapi.lib")

#include <stdio.h>
#include <windows.h>
#include <wlanapi.h>

VOID WlanNotification(WLAN_NOTIFICATION_DATA *wlanNotifData,VOID *p)
{
    if(wlanNotifData->NotificationCode == wlan_notification_acm_scan_complete)
    {
        bWait = false;
    }
    else if(wlanNotifData->NotificationCode == wlan_notification_acm_scan_fail)
    {
        printf("Scanning failed with error: %x\n", wlanNotifData->pData);
        bWait = false;

...... ......

I wanted to know how I can compile the source code that has wlanapi.h and windows.h dependency? 我想知道如何编译具有wlanapi.h和windows.h依赖项的源代码?

Please note that I want this code to run on Windows (Not Linux). 请注意,我希望此代码在Windows(而非Linux)上运行。 I am coding a Tool for simple windows users that would diagnose their Wifi security for them. 我正在为简单的Windows用户编写工具,该工具将为他们诊断其Wifi安全性。 The first step is to sense the nearest WiFi APs and their respective Encryption Types. 第一步是检测最近的WiFi AP及其各自的加密类型。 I just want to know how I can compile this code for windows platform that has a 'windows.h' or 'wlanapi.h' dependency, in the easiest possible way. 我只想知道如何以最简单的方式为具有'windows.h'或'wlanapi.h'依赖项的Windows平台编译此代码。

It's important to understand that C and C++ are portable languages, but that doesn't mean that API's are the same for different OS's - and this is a good example of that. 重要的是要了解C和C ++是可移植的语言,但这并不意味着不同操作系统的API相同-这就是一个很好的例子。

The simple solution to your problem is probably to find another source that is already working on a Linux platform. 解决您的问题的简单方法可能是找到已经在Linux平台上工作的另一个来源。 This seems to be a decent resource: http://tuxmobil.org/linux_wireless_sniffer.html 这似乎是一个不错的资源: http : //tuxmobil.org/linux_wireless_sniffer.html

If your goal is to make this code run on Linux, then you will need to find the corresponding Linux interfaces. 如果您的目标是使此代码在Linux上运行,则需要找到相应的Linux接口。 There is a question about this here: Wireless API for Linux in C or Java 这里有一个问题: 适用于C或Java的Linux无线API

Unfortunately, that's not a straight "plug-in" compatible interface for the Windows code, so you will have to make some pretty significant modifications to the code (or build a compatibility library that emulates the wlanapi.h functionality, but my rough estimate is that this is not easier!) 不幸的是,这不是Windows代码的直接“插件”兼容接口,因此您将不得不对代码进行一些相当重大的修改(或构建一个模仿wlanapi.h功能的兼容性库,但我的粗略估计是这并不容易!)

I have found a Solution to this problem. 我已经找到解决此问题的方法。

In the Question I asked about the easiest possible way to compile a code with such dependencies as 'wlanapi' and 'windows.h'. 在问题中,我询问了最简单的方法来编译具有诸如“ wlanapi”和“ windows.h”之类的依赖关系的代码。

The easiest way is to install 'Microsoft Visual Studio' on Windows box and then compile the code in the relevant IDE. 最简单的方法是在Windows框中安装“ Microsoft Visual Studio”,然后在相关的IDE中编译代码。

For Example the code in the question is a C++ code, so I would compile it ('Build') in Visual C++ 例如,问题中的代码是C ++代码,因此我将在Visual C ++中对其进行编译(“生成”)

For anyone who looks at this and is trying to compile a code that uses deep windows APIs, on a linux box, please know that it is a bad bad idea. 对于任何研究此问题并试图在Linux机器上编译使用深Windows API的代码的人,请知道这是一个坏主意。 Compile it under 'Windows SDK' or Visual Studio on a Windows box. 在Windows框的“ Windows SDK”或Visual Studio下进行编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM