Delphi中DLL的编写与调用的正确方法
我才开始才开始学习Delphi的DLL编写,按照网上的写了下面的测试程序(源码下附),可是答案却和我想的完全不一样:---------------------------...
我才开始才开始学习Delphi的DLL编写,按照网上的写了下面的测试程序(源码下附),可是答案却和我想的完全不一样:
------------------------------------------------------------------------------------------------------------------------------
program DLLTest;
{$APPTYPE CONSOLE}
uses
SysUtils,
TotalUnit in 'TotalUnit.pas';
var
x,y,z:longint;
begin
readln(x,y);
z:=Total(x,y);
writeln(z);
readln;
end.
---------------------------------------------------------------------------------------------------------------------------------
library TotalDLL;
uses
SysUtils,
Classes,
TotalUnit in 'TotalUnit.pas';
{$R *.res}
function Total(x,y:longint):longint; stdcall;
begin
Total:=x+y;
end;
exports
Total;
begin
end.
----------------------------------------------------------------------------------------------------------------------------------
unit TotalUnit;
interface
function Total(x,y:longint):longint;
implementation
function Total(x,y:longint):longint; external 'TotalDLL.dll';
end.
----------------------------------------------------------------------------------------------------------------------------------
本来运行后是计算两数和,但输出完全不对,错在哪了?另外请详细讲一下Delphi中DLL的编写与调用方法能附上例子源码更好!谢谢! 展开
------------------------------------------------------------------------------------------------------------------------------
program DLLTest;
{$APPTYPE CONSOLE}
uses
SysUtils,
TotalUnit in 'TotalUnit.pas';
var
x,y,z:longint;
begin
readln(x,y);
z:=Total(x,y);
writeln(z);
readln;
end.
---------------------------------------------------------------------------------------------------------------------------------
library TotalDLL;
uses
SysUtils,
Classes,
TotalUnit in 'TotalUnit.pas';
{$R *.res}
function Total(x,y:longint):longint; stdcall;
begin
Total:=x+y;
end;
exports
Total;
begin
end.
----------------------------------------------------------------------------------------------------------------------------------
unit TotalUnit;
interface
function Total(x,y:longint):longint;
implementation
function Total(x,y:longint):longint; external 'TotalDLL.dll';
end.
----------------------------------------------------------------------------------------------------------------------------------
本来运行后是计算两数和,但输出完全不对,错在哪了?另外请详细讲一下Delphi中DLL的编写与调用方法能附上例子源码更好!谢谢! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询