How to get beginning and length of code ? 
Author Message
 How to get beginning and length of code ?

Hi,

I'm using FPC (Win32 code on XP).

For some reasons I need to lock my program in memory using VirtualLock. I
must be sure that *all* code will be locked, including system and other
units.
How could I get (from FPC units or from Win32) the beginning address and
length of the entire program ? Is there any variable or function giving that
address ?

Thank you
Foden



Mon, 07 Nov 2005 17:56:16 GMT  
 How to get beginning and length of code ?

Quote:

> I'm using FPC (Win32 code on XP).

> For some reasons I need to lock my program in memory using
> VirtualLock.

What reasons? Just curious. It will degrade the performance of the system.
It's better to lock only parts of it.

Quote:
> I must be sure that *all* code will be locked, including
> system and other units.
> How could I get (from FPC units or from Win32) the beginning address
> and length of the entire program ? Is there any variable or function
> giving that address ?

Use GetModuleInformation() to fill a MODULEINFO structure with the base
address and the image size.

Unfortunately it seems that GetModuleInformation() is not supported under
win9x systems. You can however read the base address
(OptionalHeader->ImageBase) and the image size (OptionalHeader->SizeOfImage)
from the PE executable header. But be aware that the image can be relocated.
So it's better to query the base address with GetModuleHandle(). The handle
returned by GetModuleHandle() is the base address of the module.

You can also lock only specific parts by analysing the PE section headers
and call VirtualLock() for certain sections.

BTW: The maximum number of lockable pages for a process is 30 by default. So
don't forget to call SetProcessWorkingSetSize() to increase the maximum
number of lockable pages before you call VirtualLock().

--
www.zenobits.com



Sat, 12 Nov 2005 19:10:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. datacombobox not saving all the character even though it is within length of field length

2. Getting ASCII code of keypress

3. Q: Getting code

4. Btrieve and Titan - getting HEX codes out of btrieve file

5. Getting message "at beginning of table" ????

6. "At beginning of Table"

7. At beginning of table ???

8. question: begin error

9. DBEngineError 'at beginning of table'

10. Begin or End of table error using DBlookuplistbox component

11. beginning connection help with Oracle and D4

12. About beginning programing Pascal

 

 
Powered by phpBB® Forum Software