繁体   English   中英

在 Visual Studio 2015 中使用 Npcap 编译 VC++ 程序

[英]Compiling VC++ program with Npcap in Visual Studio 2015

我正在 Visual Studio 2015 Community Edition 中编译以下程序。

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>

int main(int argc, char **argv)
{

    pcap_if_t *alldevsp, *device;


    char errbuf[100];
    int count = 1;

    //First get the list of available devices
    printf("Finding available devices ... ");
    if (pcap_findalldevs(&alldevsp, errbuf))
    {
        printf("Error finding devices : %s", errbuf);
        exit(1);
    }
    printf("Done");

    //Print the available devices
    printf("\nAvailable Devices are :\n");
    for (device = alldevsp; device != NULL; device = device->next)
    {
        printf("%d. %s - %s\n", count, device->name, device->description);
        count++;
    }

    return 0;
}

对于 pcap,我已经从Npcap项目@GitHub下载了该库。 我安装了用于获取 DLL 并将其 SDK 库用于头文件和链接器库的版本。 DLL 的安装来自发行包 0.0.8-r2,SDK 来自 0.0.7-r9。

根据网上的几个指针如何设置环境,我有以下设置。

  1. 配置属性 -> C/C++ -> 常规 -> 附加包含目录 -> 来自 SDK 的头文件夹的路径。
  2. 配置属性 -> C/C++ -> 预处理器 -> 预处理器定义 -> WIN32 _DEBUG _CONSOLE WPCAP HAVE_REMOTE
  3. 配置属性 -> 链接器 -> 常规 -> 附加库目录 -> SDK 中库文件夹的路径。
  4. 配置属性 -> 链接器 -> 输入 -> 附加依赖项 -> wpcap.lib Packet.lib

来自发行版 exe 的 DLL 安装在 C:\\Windows\\System32\\Npcap 中。 系统是Windows 10 Home。

问题:

上面的程序编译得很好。

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>  HelloWorld.cpp
1>  HelloWorld.vcxproj -> C:\Users\xxx\documents\visual studio 2015\Projects\HelloWorld\Debug\HelloWorld.exe
1>  HelloWorld.vcxproj -> C:\Users\xxx\documents\visual studio 2015\Projects\HelloWorld\Debug\HelloWorld.pdb (Full PDB)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

当我运行它时,它抱怨缺少 wpcap.dll 文件。 我是 VS 和 VC++ 的新手,我用谷歌搜索,发现最简单的技术解决了这个问题,我将 DLL 从 System32 复制到生成 .exe 文件的文件夹中。

在此 DLL 问题消失后,但现在我明白了。

'HelloWorld.exe' (Win32): Loaded 'C:\Users\xxx\Documents\Visual Studio 2015\Projects\HelloWorld\Debug\HelloWorld.exe'. Symbols loaded.
'HelloWorld.exe' (Win32): Loaded 'C:\Windows\syswow64\ntdll.dll'. Cannot find or open the PDB file.
'HelloWorld.exe' (Win32): Loaded 'C:\Windows\syswow64\kernel32.dll'. Cannot find or open the PDB file.
'HelloWorld.exe' (Win32): Loaded 'C:\Windows\syswow64\KernelBase.dll'. Cannot find or open the PDB file.
'HelloWorld.exe' (Win32): Loaded 'C:\Windows\syswow64\ucrtbased.dll'. Cannot find or open the PDB file.
'HelloWorld.exe' (Win32): Loaded 'C:\Windows\syswow64\vcruntime140d.dll'. Cannot find or open the PDB file.
The thread 0x160c has exited with code -1073741701 (0xc000007b).
The thread 0xd5c has exited with code -1073741701 (0xc000007b).
The thread 0x16c4 has exited with code -1073741701 (0xc000007b).
The program '[9632] HelloWorld.exe' has exited with code -1073741701 (0xc000007b).

我用谷歌搜索,似乎有 64 位和 32 位 DLL 的混合。 我不知道如何开始调试这个问题。

如果有人指导我解决问题,我将不胜感激。

  1. 找到 DLL 而不是复制到 exe 文件夹的更好方法(VC++ 世界中的良好实践)。
  2. 有关如何查找导致问题的 DLL 的提示。

谢谢你的时间。

从配置来看,您的HelloWorld.exe是一个 32 位 (x86) 程序。 我假设您使用的是 x64 Windows 操作系统,因此C:\\Windows\\System32\\Npcap用于 x64 DLL。 C:\\Windows\\SysWOW64\\Npcap用于 x86 DLL。

您收到0xc000007b错误,因为您的 x86 HelloWorld.exe正在尝试加载 Npcap 的 x64 DLL,这绝对是不对的。

因此,解决方案是将 DLL( wpcap.dllPacket.dll )从C:\\Windows\\SysWOW64\\Npcap到生成 .exe 文件的文件夹中。

另一种方法是将C:\\Windows\\System32PATH环境变量中。 因此,无论 x86 和 x64 二进制文件位于何处,它们都将始终找到正确的 Npcap DLL。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM