Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-19
5
Medium Priority
?
300 Views
Last Modified: 2010-04-05
Hello,

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

greetings

William
0
Comment
Question by:SirWinston8
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 12631145
What are "base addres" and "address of application"?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 12633164
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
 

Author Comment

by:SirWinston8
ID: 12642775
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
 
LVL 20

Accepted Solution

by:
Madshi earned 1000 total points
ID: 12642926
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
 

Author Comment

by:SirWinston8
ID: 12643577
Thank you Madshi,

it works how I need it!

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

regards

William
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question