一直提示DLL中的函数未声明
下面是DLL代码:library MyDLL;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes;{$R *.res}
function MyNum(const x, y: Integer; var z:string):Integer;stdcall;
begin
if x > y then
z := '数字一大于数字二'
else if x < y then
z := '数字一小于数字二'
else if x = y then
z := '数字一等于数字二';
Result := 0;
end;
exports MyNum;begin
end.
下面是调用DLL的程序代码:type
MyNum2 = function(const x, y: Integer; var z: string):Integer; //
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
MyNum3: MyNum2; //
MyHandle: LongWord; //
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
mystr: string;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
MyNum(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr); //此处提示函数未声明
ShowMessage(mystr);
FreeLibrary(MyHandle);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MyHandle := LoadLibrary('MyDLL.dll');
if MyHandle <> 0 then
MyNum3 := GetProcAddress(MyHandle,'MyNum');
end;end.
帮忙看一下问题出在哪里,谢谢
下面是DLL代码:library MyDLL;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes;{$R *.res}
function MyNum(const x, y: Integer; var z:string):Integer;stdcall;
begin
if x > y then
z := '数字一大于数字二'
else if x < y then
z := '数字一小于数字二'
else if x = y then
z := '数字一等于数字二';
Result := 0;
end;
exports MyNum;begin
end.
下面是调用DLL的程序代码:type
MyNum2 = function(const x, y: Integer; var z: string):Integer; //
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
MyNum3: MyNum2; //
MyHandle: LongWord; //
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
mystr: string;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
MyNum(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr); //此处提示函数未声明
ShowMessage(mystr);
FreeLibrary(MyHandle);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MyHandle := LoadLibrary('MyDLL.dll');
if MyHandle <> 0 then
MyNum3 := GetProcAddress(MyHandle,'MyNum');
end;end.
帮忙看一下问题出在哪里,谢谢
解决方案 »
- 我在 fast report 里放了一个memo 能不能实现分页打印?
- 如何穿越对称型NAT实现P2P通讯?
- 新年好!
- 关于LISTVIEW 选中项的双击问题 分不够我再加哦
- 为什么没见服务器名字?
- 谁知道这个板的驱动在那里下载??? 急!
- 关于delphi adoquery撤销提交,查询的问题
- 用Ado 连接 mysql, Clientdataset.applyupdate(-1) 时 的事务处理出错
- 即时通讯(QQ/ICQ/MSN)控件
- DBGRIDEH 有多个字段,想横向比较,只有CELL 中不为0的记录有不相同的,即在一个字段表示为NO
- TADOStoredProc调用MYSql存储过程问题
- delphi word 合并单元格出错!下面是出错信息!!
MyNum2 = function(const x, y: Integer; var z: string):Integer; stdcall;
SysUtils,
Classes;{$R *.res}function MyNum(const x, y: Integer; var z:PChar):Integer;stdcall;
begin
if x > y then z := '数字一大于数字二'
else if x < y then z := '数字一小于数字二'
else if x = y then z := '数字一等于数字二';
Result := 0;
end;exports
MyNum;begin
end.
Application
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; TMyFun = function(const x, y: Integer; var z: PChar):Integer;stdcall;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
Str:PChar;
FunNum:TMyFun;
MyHandle:Cardinal;
begin
MyHandle :=LoadLibrary('MyFun.dll');
if MyHandle <>0 then
@FunNum :=GetProcAddress(MyHandle,'MyNum');
i:=FunNum(1,2,Str);
ShowMessage(IntToStr(i) + Str);
FreeLibrary(MyHandle);
end;end.
感觉你的DLL里边用Procedure应该好一些.因为你的返回值感觉根本没用!
procedure TForm1.Button1Click(Sender: TObject);
begin
MyNum3(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr); //此处提示函数未声明
ShowMessage(mystr);
FreeLibrary(MyHandle);
end;
unit mynumunit;
interface
function MyNum(const x, y: Integer; var z:string):Integer;stdcall;
inplementation
function mynum: external 'mydll';
end. 把这个单元加入主单元use子句中
type
MyNum2 = function(const x, y: Integer; var z: string):Integer;stdcall;
继续努力学习中..........
顶顶帖子,接分中........顶顶帖子,高手们也请多多赐教
http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
http://topic.csdn.net/u/20110611/12/3258c959-4f28-46b7-b5d6-46135d73036b.html
http://topic.csdn.net/u/20110722/14/89f7440b-c4d7-4c9a-a4bb-a503f5135db2.html
http://topic.csdn.net/u/20110729/10/a7bfaf06-0cf9-4580-8e91-d4e0b92066c6.html
http://topic.csdn.net/u/20110811/16/e56e7cc1-d8c9-40af-92e3-c24ca103d17d.html
http://topic.csdn.net/u/20110830/13/dfae4ca5-d2b9-4889-8a3c-6f7fb61936c9.html
http://topic.csdn.net/u/20110905/12/a1161adb-8e5d-491a-b302-c9722edf2dab.html
http://topic.csdn.net/u/20110913/16/2dbcc9db-8f71-40c5-901f-afae9026f7c2.html
http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
begin
MyNum3(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr); //此处提示函数未声明
ShowMessage(mystr);
FreeLibrary(MyHandle);
end;你搞错函数对象名了
改为
@MyNum3 := GetProcAddress(MyHandle,'MyNum');这实际上是指针函数的用法!
MyNum(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr);
应改为
MyNum3(StrToInt(Edit1.Text), StrToInt(Edit2.Text), mystr);