🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3980

Re: How to find if a DLL is still loaded

#3980
From: Dennis Jones
Date: Mon, 10 Apr 2006 19:45
68 lines
2673 bytes
"Dennis Jones" <nospam@nospam.com> wrote in message
news:443aac3c$1@newsgroups.borland.com...
>
> There's probably an easier way, but the first thing that comes to mind is
to
> enumerate the modules loaded by each process currently running on the
> system, looking for the one you're interested in.  If you don't find it,
it
> isn't loaded.

Here's a quick and dirty implementation:

bool IsDLLLoaded( const AnsiString &DLLName )
{
   bool bIsDLLLoaded = false;

   HANDLE hProcessSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS,
0 );

   if ( INVALID_HANDLE_VALUE != hProcessSnapshot )
   {
      PROCESSENTRY32 ProcessEntry;
      ProcessEntry.dwSize = sizeof( ProcessEntry );

      for ( bool bProcessFound = Process32First( hProcessSnapshot,
&ProcessEntry );
            bProcessFound;
            bProcessFound = Process32Next( hProcessSnapshot,
&ProcessEntry ) )
      {
         HANDLE hModuleSnapshot = CreateToolhelp32Snapshot(
TH32CS_SNAPMODULE, ProcessEntry.th32ProcessID );

         if ( INVALID_HANDLE_VALUE != hModuleSnapshot )
         {
            MODULEENTRY32 ModuleEntry;
            ModuleEntry.dwSize = sizeof( ModuleEntry );

            for ( bool bModuleFound = Module32First( hModuleSnapshot,
&ModuleEntry );
                  bModuleFound;
                  bModuleFound = Module32Next( hModuleSnapshot,
&ModuleEntry ) )
            {
               if ( DLLName == ModuleEntry.szModule )
               {
                  bIsDLLLoaded = true;
                  break;
               }
            }
         }

         CloseHandle( hModuleSnapshot );

         if ( bIsDLLLoaded )
         {
            break;
         }
      }

      CloseHandle( hProcessSnapshot );
   }

   return bIsDLLLoaded;
}

- Dennis
Technical Details
Message-ID: <443ab5ce$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <443a4e43$1@newsgroups.borland.com> <443aac3c$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,14aae0d621067c62
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Dennis Jones" <nospam@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <443a4e43$1@newsgroups.borland.com> <443aac3c$1@newsgroups.borland.com>
Subject: Re: How to find if a DLL is still loaded
Date: Mon, 10 Apr 2006 12:45:19 -0700
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 71.245.109.58
Message-ID: <443ab5ce$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1144698318 71.245.109.58 (10 Apr 2006 12:45:18 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail