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

馋奶兔 提交于 2019-12-24 14:06:55

问题


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?

Please note that I want this code to run on Windows (Not Linux). I am coding a Tool for simple windows users that would diagnose their Wifi security for them. The first step is to sense the nearest WiFi APs and their respective Encryption Types. 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.


回答1:


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.

The simple solution to your problem is probably to find another source that is already working on a Linux platform. This seems to be a decent resource: 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. There is a question about this here: Wireless API for Linux in C or Java

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!)




回答2:


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

The easiest way is to install 'Microsoft Visual Studio' on Windows box and then compile the code in the relevant IDE.

For Example the code in the question is a C++ code, so I would compile it ('Build') in 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. Compile it under 'Windows SDK' or Visual Studio on a Windows box.



来源:https://stackoverflow.com/questions/21621013/how-to-compile-c-code-that-has-a-wlanapi-h-and-windows-h-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!