-static BOOL
-load_toolhelp (void)
-{
- static int toolhelp_loaded = 0;
- static HMODULE dll = NULL;
-
- if (!toolhelp_loaded)
- {
- toolhelp_loaded = 1;
-#ifndef _WIN32_WCE
- dll = GetModuleHandle (_T("KERNEL32.DLL"));
-#else
- dll = LoadLibrary (L"TOOLHELP.DLL");
-#endif
- if (!dll)
- return FALSE;
-
- win32_CreateToolhelp32Snapshot =
- GETPROCADDRESS (dll, CreateToolhelp32Snapshot);
- win32_Module32First = GETPROCADDRESS (dll, Module32First);
- win32_Module32Next = GETPROCADDRESS (dll, Module32Next);
-#ifdef _WIN32_WCE
- win32_CloseToolhelp32Snapshot =
- GETPROCADDRESS (dll, CloseToolhelp32Snapshot);
-#endif
- }
-
- return (win32_CreateToolhelp32Snapshot != NULL
- && win32_Module32First != NULL
- && win32_Module32Next != NULL
-#ifdef _WIN32_WCE
- && win32_CloseToolhelp32Snapshot != NULL
-#endif
- );
-}
-
-static int
-toolhelp_get_dll_name (DWORD BaseAddress, char *dll_name_ret)
-{
- HANDLE snapshot_module;
- MODULEENTRY32 modEntry = { sizeof (MODULEENTRY32) };
- int found = 0;
-
- if (!load_toolhelp ())
- return 0;
-
- snapshot_module = win32_CreateToolhelp32Snapshot (TH32CS_SNAPMODULE,
- current_event.dwProcessId);
- if (snapshot_module == INVALID_HANDLE_VALUE)
- return 0;
-
- /* Ignore the first module, which is the exe. */
- if (win32_Module32First (snapshot_module, &modEntry))
- while (win32_Module32Next (snapshot_module, &modEntry))
- if ((DWORD) modEntry.modBaseAddr == BaseAddress)
- {
-#ifdef UNICODE
- wcstombs (dll_name_ret, modEntry.szExePath, MAX_PATH + 1);
-#else
- strcpy (dll_name_ret, modEntry.szExePath);
-#endif
- found = 1;
- break;
- }
-
-#ifdef _WIN32_WCE
- win32_CloseToolhelp32Snapshot (snapshot_module);
-#else
- CloseHandle (snapshot_module);
-#endif
- return found;
-}