编写一个DLL,其中有个function需要传入一个i:integer.我在DLL中是这样申明的:
function func1(const i: integer);integer; stdcall; export;function func1(const i: integer):integer;
begin
Showmessage(IntToStr(i) + #13 + ' -- DLL中的函数"func1"被成功调用了!');
func1:= i;
end;
在调用时:
procedure InvokeFunc(i :integer);external 'PrjDLL.dll' name 'func1';实现:
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
s: string;
begin
if InputQuery('输入','输入要传的数字', s) then
i := StrToInt(s);
InvokeFunc(i);
end;当输入了数字,如:输入8 ,显示的并不是期望的:“8-- DLL中的函数"func1"被成功调用了!”
而是“1243260-- DLL中的函数"func1"被成功调用了!”,而且不论输入什么数字都是显示“1243260-- DLL中的函数"func1"被成功调用了!”。我估计是读到了别的内存地址的内容了。删除stdcall一切正常。÷我想问的是:stdcall是起什么作用呢?一般什么时候需要用到?
function func1(const i: integer);integer; stdcall; export;function func1(const i: integer):integer;
begin
Showmessage(IntToStr(i) + #13 + ' -- DLL中的函数"func1"被成功调用了!');
func1:= i;
end;
在调用时:
procedure InvokeFunc(i :integer);external 'PrjDLL.dll' name 'func1';实现:
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
s: string;
begin
if InputQuery('输入','输入要传的数字', s) then
i := StrToInt(s);
InvokeFunc(i);
end;当输入了数字,如:输入8 ,显示的并不是期望的:“8-- DLL中的函数"func1"被成功调用了!”
而是“1243260-- DLL中的函数"func1"被成功调用了!”,而且不论输入什么数字都是显示“1243260-- DLL中的函数"func1"被成功调用了!”。我估计是读到了别的内存地址的内容了。删除stdcall一切正常。÷我想问的是:stdcall是起什么作用呢?一般什么时候需要用到?
解决方案 »
- 关于 delphi自带的TcpServer和indy的idTcpServer
- 请教一下Delphi各版本的历史情况,下学期要开这门课了。以前都弄C现在疑惑中。
- 如何重新编译ACTVEX窗体?
- 打印的问题???????????????????????????????????
- 在打印报表时,上面加的QRMemory,能否规定它一行打多少字或这一行多长??
- 那位大哥能帮我把C#转成delphi语法,小弟万分跪谢!
- 高分求购 delphi网络传输文件程序
- 有谁能帮我详解一下ADO的用法
- delphi编程
- 合并Exe的问题?
- 缺省形成的标题栏(caption)的 高度 一般 是 多少??能否改变??
- 改SQL语句,解决马上给分
function InvokeFunc(i :integer):integer; stdcall;external 'PrjDLL.dll' name 'func1';
stdcall是一种基本的处理函数参数的方式,是从C语言带过来的。按照从右往左的的顺序入栈。而你什么都不加,是默认的pascal参数入栈方式。是从左往右顺序入栈。如果你要用,一定要把参数入栈的方式声明为一致的,如果出现类似问题,请参照Delphi帮助第**********页,索引stdcall那一行。参数入栈方式还有其他的三种……解释如下:When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall. For example,function MyFunction(X, Y: Real): Real; cdecl; ...Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.The register and pascal conventions pass parameters from left to right; that is, the left most parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.
For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.
The safecall convention implements exception 揻irewalls.?On Windows, this implements interprocess COM error notification.The table below summarizes calling conventions.Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No
The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from shared libraries written in C or C++, while stdcall and safecall are recommended, in general, for calls to external code. On Windows, the operating system APIs are stdcall and safecall. Other operating systems generally use cdecl. (Note that stdcall is more efficient than cdecl.)The safecall convention must be used for declaring dual-interface methods. The pascal convention is maintained for backward compatibility. For more information on calling conventions, see Program control.
The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.
...Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.The register and pascal conventions pass parameters from left to right; that is, the left most parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.
For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.
The safecall convention implements exception "firewalls." On Windows, this implements interprocess COM error notification.The table below summarizes calling conventions.Calling conventions
Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No
The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from shared libraries written in C or C++, while stdcall and safecall are recommended, in general, for calls to external code. On Windows, the operating system APIs are stdcall and safecall. Other operating systems generally use cdecl. (Note that stdcall is more efficient than cdecl.)The safecall convention must be used for declaring dual-interface methods. The pascal convention is maintained for backward compatibility. For more information on calling conventions, see Program control.
The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.
看不懂???????????????????????????????