3

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.

learnerX
  • 1,022
  • 1
  • 18
  • 44
  • do you get an error? Or are you asking how to compile it? – Gasim Feb 07 '14 at 07:04
  • 1
    You compile it with a compiler that can target Windows. Visual Studio (the Express version is free) or MinGW or such. – Adam Feb 07 '14 at 07:11
  • I am a Linux guy and don't have much experience with Windows. I tried compiling it with g++ in Linux and Of course i got an error saying 'windows.h' not found. I am installing 'Mingw32' in my Linux Box. It would solve the 'windows.h' dependency I guess, but what about 'wlanapi.h'?? – learnerX Feb 07 '14 at 07:42

2 Answers2

3

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

Community
  • 1
  • 1
Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • Thanks for your suggestion. However please note that I want to compile this code for Windows platform and NOT for linux. I have 'edited' my original question accordingly. 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. – learnerX Feb 07 '14 at 08:23
  • Well, then you need a windows cross-compiler that runs on Linux. For example: http://www.mingw.org/wiki/LinuxCrossMinGW You may also need to get hold of the headers and libraries for the API you are using. – Mats Petersson Feb 07 '14 at 08:31
  • "i586-mingw32msvc-g++ -s -o wlansca.exe wlansca.cpp wlanscap.cpp:12:21: error: wlanapi.h: No such file or directory". Now I need to get this 'wlanapi.h' I guess and add it for mingw32 I guess? – learnerX Feb 07 '14 at 08:44
  • Yes, like I said, you may need to install the headers and libraries (and that can be harder than it seems, because some of them come in "installer packages", which means you need to run Windows code to extract the content - Wine [Windows emulator] may be a rescue here) – Mats Petersson Feb 07 '14 at 08:47
  • Ok, Since I am in a hurry and don't want to spend a lot of time diagnosing errors, I have decided to download and install 'Windows SDK' on a Windows box (Like a good boy!) and just compile my code from there. Seems much easier that way – learnerX Feb 07 '14 at 08:50
  • Yes, absolutely, much easier. – Mats Petersson Feb 07 '14 at 20:35
1

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.

learnerX
  • 1,022
  • 1
  • 18
  • 44