簡體   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