我们可以从Delphi调用Native Windows API吗?

n1k*_*ita 7 windows delphi winapi system-calls delphi-7

是否可以从Delphi应用程序中调用内核Native API?喜欢ntzw系统调用.

Dav*_*nan 14

您确实可以从Delphi调用本机API.

Delphi没有附带本机API的头文件.因此,您需要提供自己的,或使用预先存在的翻译.例如.NT API的JEDI翻译.

  • 确实,你需要来自Jedi Apilib的JwaNative.pas(+1) (7认同)

Rem*_*mko 10

正如David Heffernan所说,完全可以使用来自usermode和Delphi的Native API.你将需要Jedi Apilib的JwaNative装置.

下面是使用Native API枚举进程的小例子:(TProcessList是TObjectList的后代,但相关部分是对NtQuerySystemInformation的调用)

function EnumProcesses: TProcessList;
var
  Current: PSystemProcesses;
  SystemProcesses : PSystemProcesses;
  dwSize: DWORD;
  nts: NTSTATUS;
begin
  Result := TProcessList.Create;

  dwSize := 200000;
  SystemProcesses := AllocMem(dwSize);

  nts := NtQuerySystemInformation(SystemProcessesAndThreadsInformation,
      SystemProcesses, dwSize, @dwSize);

  while nts = STATUS_INFO_LENGTH_MISMATCH do
  begin
    ReAllocMem(SystemProcesses, dwSize);
    nts := NtQuerySystemInformation(SystemProcessesAndThreadsInformation,
      SystemProcesses, dwSize, @dwSize);
  end;

  if nts = STATUS_SUCCESS then
  begin
    Current := SystemProcesses;
    while True do
    begin
      Result.Add(TProcess.Create(Current^));
      if Current^.NextEntryDelta = 0 then
        Break;

      Current := PSYSTEM_PROCESSES(DWORD_PTR(Current) + Current^.NextEntryDelta);
    end;
  end;

  FreeMem(SystemProcesses);
end;
Run Code Online (Sandbox Code Playgroud)