首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在2013中使用NetMon API链接器错误

在2013中使用NetMon API链接器错误
EN

Stack Overflow用户
提问于 2016-02-29 15:20:50
回答 1查看 324关注 0票数 0

在VS 2013中,我在编译/链接NetmonAPI时遇到了问题。API随安装而来。Networkmonitor甚至在“帮助”中解释了如何让它在VS中工作。我按照说明如何设置它,尝试了一个帮助的例子,但失败了。我总是得到七个符号的"LNK2019"错误。

我使用的示例代码:

代码语言:javascript
复制
#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;
}

我发现的一个错误是:

  • 错误LNK2019:函数"_wmain“中未解析的外部符号"_NmCloseHandle@4”。

在这里,我的脚步:

  1. 安装Windows驱动程序工具包(WDK)
  2. 我在VS 2013中建立了一个新的控制台-Project
  3. 在项目中添加以下目录--VC++下的属性-- directorys -> Include-Dir:"C:\Program \Microsoft Network Monitor 3\API“、"C:\WinDDK\7600.16385.1\inc\api”、"C:\WinDDK\7600.16385.1\inc\ddk“
  4. 在项目中添加以下方向-VC++下的属性- directorys -> Library-Dir:"C:\Program \ 3\API“
  5. 在链接器中添加"nmapi.lib“->输入->附加依赖项

我不知道我是否有一个可弥补的问题,因为说明是针对VS 2005和2008年。

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2017-05-28 15:29:50

我认为这是32/64位的问题。

在我的例子中,我有一个带有windows 7 64位操作系统的桌面机器。

我有一个使用windows 7工具链的eclipse。

我对你犯了同样的错误,但环境不同。

我还安装了64位3.4。

正如你所看到的,它是64位的。

嗯,我已经成功地用'/machine:x64‘作为链接器选项编译了我的测试程序。

这个问题可能是没有32位支持的64位监视器库。

所以,我想你还需要和我一样的链接器选项。

下面是我使用windows 7编写的编译日志。

  1. x64 env +链接器选项

  1. x86 env +链接器选项

  1. x86 env +无链接器选项

请参阅microsoft 这里

回答太迟了,也许..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35703128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档