Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the address returned by the @ operator is not the same to the returned by the GetProcAddress function

Tags:

winapi

delphi

I need to get the address of a Win APi method (FindWindowW) , I'm using the @ operator and the GetProcAddress but both returns differents results.

var
  p1, p2 : Pointer;
begin
  p1:= @Winapi.Windows.FindWindowW;
  p2:=GetProcAddress(GetModuleHandle('user32.dll'), 'FindWindowW');
  ShowMessage(Format('p1 %p p2 %p ', [p1, p2]));
end;

Why the values returned are different?

like image 534
Salvador Avatar asked Dec 06 '13 02:12

Salvador


1 Answers

Because static linking uses a thunk jump table to call a DLL function.

p2 in your example is the correct address of the FindWindowW function in your process, while p1 is the address of a jump instruction like this

jmp dword ptr [SomeAddress]

where SomeAddress points to the actual address of the FindWindowW function.

like image 175
kludg Avatar answered Oct 18 '22 02:10

kludg