//为什么我的结果不是123?帮帮小弟吧 !俺真的没分了!
library PRO_SYS;uses
  SysUtils,
  Classes; 
type
  PPROCESSINFO = ^_ProcessInfo;
  _ProcessInfo = record
     dwSize:longword;
     end;
{$R *.res}
function GetProcessInfo(PROCESSINFO:PPROCESSINFO):integer;stdcall;
begin
   getmem(PROCESSINFO,sizeof(_ProcessInfo));
   PROCESSINFO.dwSize:=123;
   result:=1;
end;
exports   GetProcessInfo;
begin
end.//调用的单元
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
type
  PPROCESSINFO = ^_ProcessInfo;
  _ProcessInfo = record
     dwSize:longword;
     end;
var
  Form1: TForm1;implementation{$R *.dfm}
function GetProcessInfo(PROCESSINFO:PPROCESSINFO):integer;stdcall;external 'PRO_SYS.dll';
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
var t:PPROCESSINFO;
begin
  getmem(t,sizeof(_ProcessInfo));
  i:=GetProcessInfo(t);
  if i>0 then
       showmessage('t^.dwSize:  '+inttostr( t^.dwSize)) ;
end;end.

解决方案 »

  1.   

    dll中:
    function GetProcessInfo(var PROCESSINFO:PPROCESSINFO):integer;stdcall;
    begin
       getmem(PROCESSINFO,sizeof(_ProcessInfo)); //本句刪除
       PROCESSINFO^.dwSize:=123;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,tlhelp32;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    type
      PPROCESSINFO = ^_ProcessInfo;
      _ProcessInfo = record
         szExeFile:string;//问题所在 ::::为什么我要用pchar类型就不行了!全是乱码,
         end;
    var
      Form1: TForm1;implementation{$R *.dfm}function GetProcessInfo(PROCESSINFO:PPROCESSINFO):integer;
    var hand:thandle;
        i:integer;
        lppe:PROCESSENTRY32;
        found:boolean;
        name:shortstring;
    begin
      try
        i:=0;
        Hand:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
        if hand>0 then
        lppe.dwSize:= sizeof(PROCESSENTRY32);
        found:=Process32First(Hand,lppe);
         while found do
           begin
             i:=i+1;
             name:=strpas(lppe.szExeFile);
             processinfo^.szExeFile:=pchar(string(name));
             inc(processinfo);
             found:=Process32next(Hand,lppe);
           end;
           result:=i;
      except
        result:=-1;
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer; //保存函数返回值
        t:integer;//for循环步长
         myarray: PPROCESSINFO;
    begin
      getmem(myarray,sizeof(PPROCESSINFO)*2048000);
      i:=GetProcessInfo(myarray);
      if i>0 then
        for t:=1 to i do
         begin
            memo1.lines.Add('进程名:'+myarray.szExeFile);
            inc(myarray);
          end;
    end;end.
      

  3.   

    如果说用phar类型要自己申请空间的话,那该如何写程序呢?!谢谢!分不够可再加!!!!!!!!!
      

  4.   

    delphi的简单变量具有内存自动回收的功能,不过java也有。
    用pchar时先用GetMem手工分配pchar要使用的空间,用完后FreeMem手工释放,和c编程差不多。SizeOf(P)和SizeOf(P^)是不一样的,一个是指针变量的大小一个是指针变量所引用的内存的大小。