Hello,
Ntdll exports a number of variables which can be imported in FPC using "cvar".
There is a variable named LdrSystemDllInitBlock which is exported in both, the 32bit and 64bit versions of ntdll. Accessing the variable from a 64bit program works as expected but, from a 32bit program, Windows complains that the variable "_LdrSystemDllInitBlock" (note the extra underscore) is not found in ntdll.
Here is a little test program that operates as expected in 64bit but, causes the "_LdrSystemDllInitBlock entry point not found" in ntdll.
{$APPTYPE CONSOLE}
{$TYPEDADDRESS ON}
{$LONGSTRINGS OFF}
{ --------------------------------------------------------------------------- }
{$ifdef VER90}
{$FATAL this program can only be compiled with FPC}
{$endif}
{ --------------------------------------------------------------------------- }
program _cvars;
uses
sysutils
;
var
LdrSystemDllInitBlock : DWORD; cvar; external 'ntdll';
begin
writeln;
writeln;
writeln(' address of LdrSystemDllInitBlock is : ',
'$' + IntToHex(ptruint(@LdrSystemDllInitBlock), 0));
writeln;
writeln(' value of LdrSystemDllInitBlock is : ',
LdrSystemDllInitBlock);
writeln;
writeln;
writeln('press ENTER/RETURN to end this program');
readln;
end.
My question is: why is it looking for the variable name preceded by an "_" when the program is compiled for 32bit and what are the steps to take to eliminate the problem ?
Thank you for your help.
Attached is a screenshot of the error message and verification that the export is present in the 32bit version of ntdll (without the "_")