//为什么我的结果不是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.
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.
解决方案 »
- 查询2张表的数据然后返回给Listview问题~请兄弟们进来看看!
- 再请帮忙测试网站
- 打印高手请进来看一下,有关Printer.Canvas.TextOut打印出错,不知道错在哪里?分不够我可以加!
- 想做个抽奖程序,大家给点建议(up有分)
- messagebox怎么用啊 在线等
- 如何用一个dbgrid显示多张表的内容?
- 关于统计方面?
- 急,请过来看看再加一百分,不够再加
- 我一直都是学CB5的,但其编译速度实在太慢,现在有意于Borland的Delphi,大家怎么看!
- 系统退出时的问题?(ado连sqlserver)
- ado控件哪些比较常用,与传统的ado对象比较,使用哪些比较好。
- 如何在FastReport中实现用户自定义字段打印!!!
function GetProcessInfo(var PROCESSINFO:PPROCESSINFO):integer;stdcall;
begin
getmem(PROCESSINFO,sizeof(_ProcessInfo)); //本句刪除
PROCESSINFO^.dwSize:=123;
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.
用pchar时先用GetMem手工分配pchar要使用的空间,用完后FreeMem手工释放,和c编程差不多。SizeOf(P)和SizeOf(P^)是不一样的,一个是指针变量的大小一个是指针变量所引用的内存的大小。