0

I have problems compiling/linking the NetmonAPI in VS 2013. The API comes with installing MS Networkmonitor. Networkmonitor even has a explanation in the help how you can get it to work in VS. I followed the instructions how to set it up, tried an example from the help and failed. I always get the "LNK2019" Error for seven symbols.

The example code i'm using:

#include "Stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "objbase.h"
#include "ntddndis.h"
#include "NMApi.h"

void __stdcall 
MyFrameIndication(HANDLE hCapEng, ULONG ulAdaptIdx, PVOID pContext, HANDLE hRawFrame)
{
    HANDLE capFile = (HANDLE)pContext;
    NmAddFrame(capFile, hRawFrame);
}

int __cdecl wmain(int argc, WCHAR* argv[])
{
    ULONG ret;
    ULONG adapterIndex = 0;

    if(2 == argc)
        adapterIndex = _wtol(argv[1]);

    // Open a capture file for saving frames.
    HANDLE myCapFile;
    ULONG CapSize;
    ret = NmCreateCaptureFile(L"20sec.cap", 20000000, NmCaptureFileWrapAround, &myCapFile, &CapSize);
    if(ret != ERROR_SUCCESS)
    {
        wprintf(L"Error opening capture file, 0x%X\n", ret);
        return ret;
    }

    // Open the capture engine.
    HANDLE myCaptureEngine;
    ret = NmOpenCaptureEngine(&myCaptureEngine);
    if(ret != ERROR_SUCCESS)
    {
        wprintf(L"Error opening capture engine, 0x%X\n", ret);
        NmCloseHandle(myCapFile);
        return ret;
    }

    //Configure the adapter.
    ret = NmConfigAdapter(myCaptureEngine, adapterIndex, MyFrameIndication, myCapFile);
    if(ret != ERROR_SUCCESS)
    {
        wprintf(L"Error configuration adapter, 0x%X\n", ret);
        NmCloseHandle(myCaptureEngine);
        NmCloseHandle(myCapFile);
        return ret;
    }

    //Start capturing frames.
    wprintf(L"Capturing for 20 seconds\n");
    NmStartCapture(myCaptureEngine, adapterIndex, NmLocalOnly);

    Sleep(20000);

    wprintf(L"Stopping capture\n");
    NmStopCapture(myCaptureEngine, adapterIndex);

    NmCloseHandle(myCaptureEngine);
    NmCloseHandle(myCapFile);

    return 0;
}

One of the errors i get:

  • error LNK2019: unresolved external symbol "_NmCloseHandle@4" in Funktion "_wmain".

Here my steps:

  1. Installation of the Windows Driver Kit (WDK)
  2. I set up a new Console-Project in VS 2013
  3. Adding following directorys in the project-properties under VC++- Directorys --> Include-Dir: "C:\Program Files\Microsoft Network Monitor 3\API", "C:\WinDDK\7600.16385.1\inc\api", "C:\WinDDK\7600.16385.1\inc\ddk"
  4. Adding following directorys in the project-properties under VC++- Directorys --> Library-Dir: "C:\Program Files\Microsoft Network Monitor 3\API"
  5. Adding "nmapi.lib" to Linker-->Input-->Additional Dependencies

I dont know if i maybe have a compability problem, cause the instructions are for VS 2005 and 2008..

Thanks in advance!

tommybee
  • 2,409
  • 1
  • 20
  • 23
kyi
  • 43
  • 1
  • 10
  • It's not able to find or link to the nmapi.lib library. Try adding this line to the top of the file, just as a test to determine if it makes any difference: "#pragma comment(lib, "nmapi.lib")" without the quotes. Then make sure you also set the "Library Include Directories" to the path where the lib is stored. HTH. – kvr Feb 29 '16 at 17:30
  • I added the line and get the same failure... I'm getting now 108 additional failures like syntax-failures in "stdio.h". But when i copy the required headers from the WDK to my project, i'm just getting the 7 old failures again. There is also a "NMAPI.ddl" in the installation directory of NetworkMonitor. Do i have to copy it to a certain directory? – kyi Mar 01 '16 at 06:24

1 Answers1

0

I think it's a 32/64 bit problem.

In my case, I have a desktop machine with windows 7 64 bit OS.

I have a eclipse with windows sdk 7 toolchain.

I've got the same errors with yours but different environment.

enter image description here

I also have the 64 bit Microsoft Network Monitor 3.4 install.

enter image description here

It is a 64 bit one as you see.

Well, I have successfully compiled my test program with '/machine:x64' as a linker option.

This problem could be a 64-bit monitor library without 32-bit support.

So, I think you need one more linker option same with me.

Here is my compilation log with a windows sdk 7.

  1. x64 env + linker option

enter image description here

  1. x86 env + linker option

enter image description here

  1. x86 env + no linker option

enter image description here

Refer to the microsoft site here.

Too late answer, maybe..

tommybee
  • 2,409
  • 1
  • 20
  • 23