Windows: PCAP: Fix Npcap loading for _UNICODE
parent
496a007da3
commit
71fc039689
|
|
@ -1,4 +1,5 @@
|
||||||
#include "icsneo/platform/windows/internal/pcapdll.h"
|
#include "icsneo/platform/windows/internal/pcapdll.h"
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
|
|
@ -27,22 +28,19 @@ bool PCAPDLL::ok() const
|
||||||
|
|
||||||
PCAPDLL::PCAPDLL()
|
PCAPDLL::PCAPDLL()
|
||||||
{
|
{
|
||||||
|
DLL_DIRECTORY_COOKIE cookie = 0;
|
||||||
#ifdef NPCAP
|
#ifdef NPCAP
|
||||||
BOOL(WINAPI * SetDllDirectory)(LPCTSTR);
|
TCHAR dllPath[512] = { 0 };
|
||||||
char sysdir_name[512];
|
int len = GetSystemDirectory(dllPath, 480); // be safe
|
||||||
int len;
|
if (len) {
|
||||||
SetDllDirectory = (BOOL(WINAPI*)(LPCTSTR)) GetProcAddress(GetModuleHandle("kernel32.dll"), "SetDllDirectoryA");
|
_tcscat_s(dllPath, 512, TEXT("\\Npcap"));
|
||||||
if (SetDllDirectory != NULL)
|
cookie = AddDllDirectory(dllPath);
|
||||||
{
|
|
||||||
len = GetSystemDirectory(sysdir_name, 480); // be safe
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
strcat(sysdir_name, "\\Npcap");
|
|
||||||
SetDllDirectory(sysdir_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
dll = LoadLibrary(TEXT("wpcap.dll"));
|
dll = LoadLibraryEx(TEXT("wpcap.dll"), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS);
|
||||||
|
|
||||||
|
if (cookie)
|
||||||
|
RemoveDllDirectory(cookie);
|
||||||
|
|
||||||
if(dll == NULL) {
|
if(dll == NULL) {
|
||||||
closeDLL();
|
closeDLL();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue