diff --git a/platform/windows/internal/include/pcapdll.h b/platform/windows/internal/include/pcapdll.h index ffd2efe..3cabd60 100644 --- a/platform/windows/internal/include/pcapdll.h +++ b/platform/windows/internal/include/pcapdll.h @@ -4,12 +4,17 @@ #include #include #include +#include namespace icsneo { // Helper loader for the PCAP DLL class PCAPDLL { public: + // The first time we use the DLL we keep it in here and it won't get freed until the user unloads us (for speed reasons) + static std::shared_ptr lazyLoadHolder; + static bool lazyLoaded; + // Functions typedef int(__cdecl* PCAPFINDDEVICE)(char* source, struct pcap_rmtauth* auth, pcap_if_t** alldevs, char* errbuf); typedef pcap_t*(__cdecl* PCAPOPEN)(const char* source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth* auth, char* errbuf); diff --git a/platform/windows/internal/pcapdll.cpp b/platform/windows/internal/pcapdll.cpp index 3c2e8a1..7e3ac39 100644 --- a/platform/windows/internal/pcapdll.cpp +++ b/platform/windows/internal/pcapdll.cpp @@ -2,7 +2,15 @@ using namespace icsneo; +std::shared_ptr PCAPDLL::lazyLoadHolder; +bool PCAPDLL::lazyLoaded = false; + PCAPDLL::PCAPDLL() { + if(!lazyLoaded) { + lazyLoaded = true; + lazyLoadHolder = std::make_shared(); + } + dll = LoadLibrary("wpcap.dll"); if(dll == NULL) {