Dll的问题,请大家帮忙!(50分)

  • 主题发起人 主题发起人 1_1_1_1
  • 开始时间 开始时间
1

1_1_1_1

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL问题:
DLL代码:
Project1.dpr文件内容:
library Project1;
{ 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,
Unit1 in 'Unit1.pas';
{$R *.RES}
exports
Mess;
begin
end.

Unit1.pas单元内容:
unit Unit1;
interface
function Mess(value: string): string;
stdcall;
implementation
function Mess(value: string): string;
begin
Result:=value;
end;

end.

调用DLL代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
function Mess(value: string): string;
stdcall;
external 'Project1.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(Mess('中国'));
end;

end.

问题:
单击按钮后显示消息框点击确定后就显示错误:“Invalid pointer operation.”
请问是什么原因?谁能告诉我呢?
先谢了
tang_8717@163.com
 
{ 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. }
 
1:.function Mess(value: string): string;
stdcall;
这里面不要用 string类型,换成pchar类型
2:你的dll文件放到system下或者是你工程的同一目录下
 
在DLL和调用的单元里的uses里要加上ShareMem单元,此单元必须放在第一个。
 
如果要用string该怎么办?
 
DLL中有函数:
procedure ChangeLang(Control:TWinControl);
export;
请问参数Control赋什么值呢,
我这样用有错误:
procedure ChangeLang(Control:TWinControl);
external 'GB_BIG5.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
ChangeLang(Application.MainForm);
end;

错误提示为:“ "Form "is not a valid component name .”
 
多人接受答案了。
 

Similar threads

后退
顶部