Re: How to get imagebase after a DLL gets loaded
- From: "Kevin" <kevin11@xxxxxxxxxxx>
- Date: Tue, 12 Dec 2006 02:41:01 -0800
"anton bassov" <soviet_bloke@xxxxxxxxxxx> wrote in message
news:1165653114.737755.43110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Kevin,
I am really sorry, but you don't seem to change - again, you jumped
into a discussion without having a slightest idea what it is all
about......
Here, try this... imagine that you have written a very useful library
routine, and it requres the hinstance. Can you predict what name the
application programmer will choose for the variable they use to store the
hinstace passed to DllMain?
We are speaking about obtaining and using DLL module's base address
*FROM WITHIN DLL MODULE ITSELF*,
The author of a useful library routine that is running within the dll may
NOT be the author of the "DLL MODULE ITSELF".
The source code may have been copied from another project, pasted in from a
database of snippets, linked-in from a static .lib, or be executing from
within some other .DLL.
It seems like you have not written much code that was reused, because
otherwise the value in this would not be so hard for you to see.
As
I said, in latter case use of VirtualQuery() may be justified if you
don't know the name of the target module
For library writers, not only do they not know the name of the target
module, they do not know the names of any of the variables within the
module.
Unless the library writer requires the user of the code to instantiate a
variable using a specific name, so that it is resolved at link-time.
One alternative is for the library writer to simply obtain the necessary
values at run-time, from within the library.
However, Will said that VirtualQuery() may be used for this purpose
*FROM WITHIN* the target DLL module as well, which started off our
discussion. This is nothing more than just illogical design,
Hopefully now you can see that there are cases where the author of code
executing in a DLL is not necessarily the author of the DLL.
If the goal is code-reuse -- which all library writers strive to maximize --
then eliminating things like InitCommonControls() is a Good Thing.
so that
the whole discussion is all about why (and if) such design may be
justified
Hopefully now you can see that obtaining a value at run-time vs. storing the
value at start-up can be a beneficial trade-off.
The trade-off is 100,000 GetProcAddress calls in 1/4 of a second, vs. the
time spent tracking down unresolved external errors because the library
routine expects "extern HINSTANCE
mySuperFancilyNamed_Variable_For_Holding_The_HINSTANCE".
Your whole post is all about obtaining DLL's based address from its
client code, and, hence, is totally unrelated to our discussion......
A "client" is a "user of" something.
A "client" of a "library" is an executable: exe, dll. .
The author of the executable may not be the author of all the code in the
executable. Some of the code within the executable may have been written by
someone else.
William uses the design pattern of obtaining a value at run-time within his
library routine, so that clients of his library routine do not need to
instantiate specially-named variables, or call an otherwise unnecessary
initialization routine.
It sounds like William writes the kind of code that other programmers could
find useful, so I can understand how that does not make sense to you.
.
- Follow-Ups:
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- References:
- How to get imagebase after a DLL gets loaded
- From: Jack
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: William DePalo [MVP VC++]
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- Re: How to get imagebase after a DLL gets loaded
- From: Kevin
- Re: How to get imagebase after a DLL gets loaded
- From: anton bassov
- How to get imagebase after a DLL gets loaded
- Prev by Date: Re: FileCopy overwrites the existing file
- Next by Date: Re: program runs almost twice as slow on 2 CPU machine when 1 CPU
- Previous by thread: Re: How to get imagebase after a DLL gets loaded
- Next by thread: Re: How to get imagebase after a DLL gets loaded
- Index(es):
Relevant Pages
|
Loading