Make sure GetModuleHandle(_T("kernel32.dll") succeeds.
If it doesn't, we're living in the Twilight Zone - that's like not finding libc/libSystem/whatever-your-UN*X-calls-it on a UN*X - but this should at least remove one complaint from Visual Studio Code Analyzer. Change-Id: Iccb568ea022ac28be962ab3fec5bccdfdf69ac13 Reviewed-on: https://code.wireshark.org/review/26165 Petri-Dish: Guy Harris <guy@alum.mit.edu> Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
768488d21e
commit
fe363c540e
|
@ -499,28 +499,32 @@ ws_init_dll_search_path()
|
|||
|
||||
typedef BOOL (WINAPI *SetDllDirectoryHandler)(LPCTSTR);
|
||||
SetDllDirectoryHandler PSetDllDirectory;
|
||||
HMODULE kernel32_handle;
|
||||
|
||||
PSetDllDirectory = (SetDllDirectoryHandler) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetDllDirectoryW");
|
||||
if (PSetDllDirectory) {
|
||||
dll_dir_set = PSetDllDirectory(_T(""));
|
||||
if (dll_dir_set) {
|
||||
/* Do not systematically add Npcap path as long as we favor WinPcap over Npcap. */
|
||||
h_scm = OpenSCManager(NULL, NULL, 0);
|
||||
if (h_scm) {
|
||||
h_serv = OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
|
||||
if (h_serv) {
|
||||
CloseServiceHandle(h_serv);
|
||||
npf_found = TRUE;
|
||||
kernel32_handle = GetModuleHandle(_T("kernel32.dll"));
|
||||
if (kernel32_handle != NULL) {
|
||||
PSetDllDirectory = (SetDllDirectoryHandler) GetProcAddress(kernel32_handle, "SetDllDirectoryW");
|
||||
if (PSetDllDirectory) {
|
||||
dll_dir_set = PSetDllDirectory(_T(""));
|
||||
if (dll_dir_set) {
|
||||
/* Do not systematically add Npcap path as long as we favor WinPcap over Npcap. */
|
||||
h_scm = OpenSCManager(NULL, NULL, 0);
|
||||
if (h_scm) {
|
||||
h_serv = OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
|
||||
if (h_serv) {
|
||||
CloseServiceHandle(h_serv);
|
||||
npf_found = TRUE;
|
||||
}
|
||||
CloseServiceHandle(h_scm);
|
||||
}
|
||||
CloseServiceHandle(h_scm);
|
||||
}
|
||||
if (!npf_found) {
|
||||
/* npf service was not found, so WinPcap is not (properly) installed.
|
||||
Add Npcap folder to libraries search path. */
|
||||
retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH);
|
||||
if (0 < retval && retval <= MAX_PATH) {
|
||||
wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap");
|
||||
dll_dir_set = PSetDllDirectory(npcap_path_w);
|
||||
if (!npf_found) {
|
||||
/* npf service was not found, so WinPcap is not (properly) installed.
|
||||
Add Npcap folder to libraries search path. */
|
||||
retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH);
|
||||
if (0 < retval && retval <= MAX_PATH) {
|
||||
wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap");
|
||||
dll_dir_set = PSetDllDirectory(npcap_path_w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue