2016-08-04 75 views
0

我正在編譯Visual Studio 2015 Community Edition中的以下程序。在Visual Studio 2015中使用Npcap編譯VC++程序

#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 project @ 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. 配置屬性 - >鏈接器 - >輸入 - >附加依賴 - >自發布EXE wpcap.lib PACKET.LIB

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++,我用Google搜索和最簡單的技術來解決這個問題,我將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. 更好的方法(在VC++世界的良好做法)找到DLL而不是複製到exe文件夾。
  2. 有關如何找到哪個DLL導致問題的提示。

謝謝你的時間。

回答

0

從配置中,您的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.dll,Packet.dll)從C:\Windows\SysWOW64\Npcap複製到生成.exe文件的文件夾中。

另一種方法是將C:\Windows\System32添加到PATH環境變量中。因此,無論您的x86和x64二進制文件位於何處,它都會找到正確的Npcap DLL。

+0

非常感謝您看看它,它解決了這個問題 –

相關問題