Windows: PCAP: Fix WinPCAP loading

Used when LIBICSNEO_NPCAP_INCLUDE_DIR is not defined
v0.3.0-dev
Paul Hollinsky 2022-02-14 19:24:46 -05:00
parent 0ded5508c1
commit 4fd65d85c8
1 changed files with 4 additions and 2 deletions

View File

@ -28,19 +28,21 @@ bool PCAPDLL::ok() const
PCAPDLL::PCAPDLL() PCAPDLL::PCAPDLL()
{ {
#ifdef NPCAP // Use -DLIBICSNEO_NPCAP_INCLUDE_DIR when configuring, point towards the npcap includes
DLL_DIRECTORY_COOKIE cookie = 0; DLL_DIRECTORY_COOKIE cookie = 0;
#ifdef NPCAP
TCHAR dllPath[512] = { 0 }; TCHAR dllPath[512] = { 0 };
int len = GetSystemDirectory(dllPath, 480); // be safe int len = GetSystemDirectory(dllPath, 480); // be safe
if (len) { if (len) {
_tcscat_s(dllPath, 512, TEXT("\\Npcap")); _tcscat_s(dllPath, 512, TEXT("\\Npcap"));
cookie = AddDllDirectory(dllPath); cookie = AddDllDirectory(dllPath);
} }
#endif
dll = LoadLibraryEx(TEXT("wpcap.dll"), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS); dll = LoadLibraryEx(TEXT("wpcap.dll"), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS);
if (cookie) if (cookie)
RemoveDllDirectory(cookie); RemoveDllDirectory(cookie);
#else // Otherwise we'll use WinPCAP, or npcap in compatibility mode
dll = LoadLibrary(TEXT("wpcap.dll"));
#endif
if(dll == NULL) { if(dll == NULL) {
closeDLL(); closeDLL();