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:
- Installation of the Windows Driver Kit (WDK)
- I set up a new Console-Project in VS 2013
- 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"
- Adding following directorys in the project-properties under VC++- Directorys --> Library-Dir: "C:\Program Files\Microsoft Network Monitor 3\API"
- 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!