Base-address and address of my application like DELPHI-Debug Module-view

Hello,

how can I get the base addres and address of my application

greetings

William
SirWinston8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZhaawZSoftware DeveloperCommented:
What are "base addres" and "address of application"?
0
MadshiCommented:
The base address of your application is "pointer(HInstance)". I've no idea what you mean with "address of application", though. Are you aware that each process in 32bit Windows programming has its own address/memory context?
0
SirWinston8Author Commented:
Hello,

thanks for your comments!

First step is done with "pointer(HInstance)", and thanks to Madshi for comment about memory context!

With application-address, I mean the entry point of the application, it's differs from that what are in the map-file from the linker.

If you are debuging a application you can call inside delphi the module-view and on the right side of the window there is a list of all
entry points are used in your application. The last entry is the application and it's real entry point, this is the address that I want
to get in runtime of my application.

I hope you understand what I mean, cause sometimes my english is ...

regards

William
0
MadshiCommented:
Some parts of the code below are copied from my unit "madTools" (which is part of my freeware package "madBasic", see http://madshi.net ). You can call the code below with "myEntryPoint := GetEntryPoint(HInstance)".

const
  // PE header constants
  CENEWHDR = $003C;  // offset of new EXE header
  CEMAGIC  = $5A4D;  // old EXE magic id:  'MZ'
  CPEMAGIC = $4550;  // NT portable executable

function GetImageNtHeaders(module: dword) : PImageNtHeaders;
begin
  result := nil;
  try
    if word(pointer(module)^) = CEMAGIC then begin
      result := pointer(module + dword(pointer(module + CENEWHDR)^));
      if result^.signature <> CPEMAGIC then
        result := nil;
    end;
  except result := nil end;
end;

function GetEntryPoint(module: dword) : pointer;
var nh : PImageNtHeaders;
begin
  nh := GetImageNtHeaders(module);
  if (nh <> nil) and (nh^.OptionalHeader.AddressOfEntryPoint <> 0) then
    dword(result) := module + nh^.OptionalHeader.AddressOfEntryPoint
  else
    result := nil;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SirWinston8Author Commented:
Thank you Madshi,

it works how I need it!

I visit your web site... impressing...

regards

William
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.