BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to find if a DLL is still loaded
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
David
Guest





PostPosted: Mon Apr 10, 2006 4:23 am    Post subject: How to find if a DLL is still loaded Reply with quote



I wish to know if a DLL which is loaded from another process is still loaded
and running. I don't call the DLL myself but just wish to know if it is
still loaded in memory.

Is this possible ??

thanks in advance
David
Back to top
Bob Gonder
Guest





PostPosted: Mon Apr 10, 2006 6:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote



Boba wrote:

Quote:
"David" wrote in message
I wish to know if a DLL which is loaded from another process is still
loaded
and running. I don't call the DLL myself but just wish to know if it is
still loaded in memory.


try to rename/delete the file.

Might be nicer to use
if( 0 == access(filename,2) )
{ //DLL is free
}else{
//DLL in use or read-only
}
Back to top
Boba
Guest





PostPosted: Mon Apr 10, 2006 6:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote



"David" <davids (AT) unite (DOT) com.au> wrote in message
news:443a4e43$1 (AT) newsgroups (DOT) borland.com...
Quote:
I wish to know if a DLL which is loaded from another process is still
loaded
and running. I don't call the DLL myself but just wish to know if it is
still loaded in memory.

Is this possible ??

thanks in advance
David

try to rename/delete the file.
Back to top
Dennis Jones
Guest





PostPosted: Mon Apr 10, 2006 8:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"David" <davids (AT) unite (DOT) com.au> wrote in message
news:443a4e43$1 (AT) newsgroups (DOT) borland.com...
Quote:
I wish to know if a DLL which is loaded from another process is still
loaded
and running. I don't call the DLL myself but just wish to know if it is
still loaded in memory.

Is this possible ??


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.

See the following link for how to enumerate all of the processes and modules
in the system:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/bas
e/taking_a_snapshot_and_viewing_processes.asp

- Dennis
Back to top
Dennis Jones
Guest





PostPosted: Mon Apr 10, 2006 9:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"Dennis Jones" <nospam (AT) nospam (DOT) com> wrote in message
news:443aac3c$1 (AT) newsgroups (DOT) borland.com...
Quote:

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
Back to top
Ed Mulroy
Guest





PostPosted: Mon Apr 10, 2006 10:06 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

I think that worked under 16 bit Windows but under Win32 I don't think
access will tell if the file is loaded.

It calls GetFileAttribues and massages the result to decide what to return.
Nothing in the result tells if the file is loaded.

.. Ed

Quote:
Bob Gonder wrote in message
news:tf3l32phnths5uo1u53tbh73rsl42315mr (AT) 4ax (DOT) com...

I wish to know if a DLL which is loaded from another process is
still loaded and running. I don't call the DLL myself but just wish
to know if it is still loaded in memory.

try to rename/delete the file.

Might be nicer to use
if( 0 == access(filename,2) )
{ //DLL is free
}else{
//DLL in use or read-only
}
Back to top
Bob Gonder
Guest





PostPosted: Mon Apr 10, 2006 10:06 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

Ed Mulroy wrote:

Quote:
I think that worked under 16 bit Windows but under Win32 I don't think
access will tell if the file is loaded.

It calls GetFileAttribues and massages the result to decide what to return.
Nothing in the result tells if the file is loaded.

Ok, then open file with write access will fail if in use, and doesn't
mess with the file if it isn't in use, as rename or delete would.
Back to top
Boba
Guest





PostPosted: Tue Apr 11, 2006 5:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"Dennis Jones" <nospam (AT) nospam (DOT) com> wrote in message
news:443aac3c$1 (AT) newsgroups (DOT) borland.com...
Quote:
...
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.

been there, done that...

if a module is not curremtly beeing used by any of the software visible to
UI via what you're talking about, there are still tons of software running
in below UI level that may still need those modules in which case you may
think the module is not in use: try to delete... if it fails - keep digging
deeper.
I still don't understand what David (the op) is trying to achieve.
Back to top
David
Guest





PostPosted: Tue Apr 11, 2006 5:56 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

Quote:
I still don't understand what David (the op) is trying to achieve.

The DLL sends messages to my app but I don't send messages back. If the user
exits the app then I would like to warn the user that there is still a DLL
trying to communicate with it before the user exits. Therefore I need to
know if the DLL is still in use.

Actually I do have access to source code for the DLL so maybe I could do
something from the DLL end. I asked here once whether or not you could send
messages to a DLL and it wasn't a simple proposition either.

regards
david




"Boba" <Boba (AT) somewhere (DOT) world> wrote in message
news:443bd8e0$1 (AT) newsgroups (DOT) borland.com...
Quote:
"Dennis Jones" <nospam (AT) nospam (DOT) com> wrote in message
news:443aac3c$1 (AT) newsgroups (DOT) 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.

been there, done that...
if a module is not curremtly beeing used by any of the software visible to
UI via what you're talking about, there are still tons of software running
in below UI level that may still need those modules in which case you may
think the module is not in use: try to delete... if it fails - keep
digging
deeper.
I still don't understand what David (the op) is trying to achieve.

Back to top
Dennis Jones
Guest





PostPosted: Tue Apr 11, 2006 7:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"Boba" <Boba (AT) somewhere (DOT) world> wrote in message
news:443bd8e0$1 (AT) newsgroups (DOT) borland.com...

Quote:
been there, done that...
if a module is not curremtly beeing used by any of the software visible to
UI via what you're talking about, there are still tons of software running
in below UI level that may still need those modules in which case you may
think the module is not in use: try to delete... if it fails - keep
digging
deeper.

Can you explain what you mean by, "visible to the UI" and "below UI level"?

CreateToolhelp32Snapshot has no notion of what's "visible to the UI" or
"below UI level." According to MSDN, using the TH32CS_SNAPPROCESS flag
results in a list of "...all processes in the system." Can you provide an
example of a process that would not be in the list of "all processes in the
system?"

- Dennis
Back to top
Boba
Guest





PostPosted: Wed Apr 12, 2006 6:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"David" <davids (AT) unite (DOT) com.au> wrote in message
news:443c5e6a (AT) newsgroups (DOT) borland.com...
Quote:
...
Actually I do have access to source code for the DLL ...

that always helps.

Quote:
I asked here once whether or not you could send
messages to a DLL and it wasn't a simple proposition either.

a dll is no different from any other application with an msg pump.
Back to top
David
Guest





PostPosted: Wed Apr 12, 2006 9:36 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

Hello Boba

So how do you tap into the message que of a DLL ??

Do you have any examples ??

Regards
David


"Boba" <Boba (AT) somewhere (DOT) world> wrote in message
news:443d2e58$1 (AT) newsgroups (DOT) borland.com...
Quote:
"David" <davids (AT) unite (DOT) com.au> wrote in message
news:443c5e6a (AT) newsgroups (DOT) borland.com...
...
Actually I do have access to source code for the DLL ...

that always helps.

I asked here once whether or not you could send
messages to a DLL and it wasn't a simple proposition either.

a dll is no different from any other application with an msg pump.

Back to top
David
Guest





PostPosted: Thu Apr 13, 2006 6:08 am    Post subject: Re: How to find if a DLL is still loaded Reply with quote

Hello

The DLL is loaded after the exceutable is run. I don't have access to the
source code of the calling app, only the DLL.

regards
david


"Boba" <Boba (AT) somewhere (DOT) world> wrote in message
news:443e5780$1 (AT) newsgroups (DOT) borland.com...
Quote:
"David" <davids (AT) unite (DOT) com.au> wrote in message
news:443de373 (AT) newsgroups (DOT) borland.com...
Hello Boba

So how do you tap into the message que of a DLL ??

Do you have any examples ??

Regards
David


Hello David;
are you talking about a dll loaded prio your code starts?
is it a library you attach? is it something you coded?

Back to top
Boba
Guest





PostPosted: Thu Apr 13, 2006 3:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"David" <davids (AT) unite (DOT) com.au> wrote in message
news:443de373 (AT) newsgroups (DOT) borland.com...
Quote:
Hello Boba

So how do you tap into the message que of a DLL ??

Do you have any examples ??

Regards
David


Hello David;

are you talking about a dll loaded prio your code starts?
is it a library you attach? is it something you coded?
Back to top
Boba
Guest





PostPosted: Thu Apr 13, 2006 3:03 pm    Post subject: Re: How to find if a DLL is still loaded Reply with quote

"Dennis Jones" <nospam (AT) nospam (DOT) com> wrote in message
news:443bf6f6$1 (AT) newsgroups (DOT) borland.com...
Quote:
...
Can you provide an example of a process that would not be
in the list of "all processes in the system?"


if you have an nt handy, look to see if the Client Server Runtime
Process
is running; if so - is the module loaded? what do you use to list 'all'
the modules curently loaded?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.