*.dll questions...

Started by
2 comments, last by llvllatrix 21 years, 9 months ago
Question 1: If i am writing a dll, can i import from another dll? Question 2: If i start a program and havn''t used a dll''s functions yet, can i replace that dll with another (i mean like copy & paste over it)?
Advertisement
quote:Original post by llvllatrix
Question 1:
If i am writing a dll, can i import from another dll?

yes.
quote:
Question 2:
If i start a program and havn''t used a dll''s functions yet, can i replace that dll with another (i mean like copy & paste over it)?

if you are implicitly linked to the dll, through a lib file, then that dll will be loaded and you can''t (easily) replace it with anything. however, you can use LoadLibrary to load a specific dll, and use GetProcAddress to obtain addresses of functions within that dll.

---
Come to #directxdev IRC channel on AfterNET
quote:Original post by llvllatrix
Question 2:
If i start a program and havn''t used a dll''s functions yet, can i replace that dll with another (i mean like copy & paste over it)?

Let''s say Quake2.exe started, but haven''t used gamex86.dll function yet. BUT gamex86.dll is already loaded... then you can''t overwrite it - "Access Denied". Is this what you want?
"after many years of singularity, i'm still searching on the event horizon"
quote:Original post by llvllatrix
Question 2:
If i start a program and havn''t used a dll''s functions yet, can i replace that dll with another (i mean like copy & paste over it)?


A pe file contains information identifying any dlls that are statically linked with it. When an executable is launched the OS loading code retrieves this information and maps those dlls into the virtual address space of the associated process. If a dll doesn''t exist the process exits without ever executing the code from the entry point function (eg WinMain or main).

If you write code to copy over a dll on disk from a process created by a pe file that is statically linked with same dll, the process that does the copying will not be able to use the functions from the replacement dll as the original dll image has already been mapped.

If the process replaces the dll and then calls LoadLibrary to load the dll, then the replacement dll will be mapped instead.

This holds as well if the copy is made using Explorer or some other file manager. Once the dll has been mapped into a process that mapping is what the process will use.

It sounds like you want to do some API hooking. Take a look at the articles at www.internals.com. There''s one there regarding this and it has a lot of additional reference links too.


"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement