调用Dll报写出错,请高手帮忙!

jakefj 2009-04-07 10:08:56
加精
我的例子:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi, ShlObj;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public

{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
Function EnPassWord(PwdValue: String): String;stdcall;external 'Login.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
sPwdValue: String;
begin
sPwdValue := EnPassWord('AAA');
//showmessage(sPwdValue);
end;

end.
...全文
401 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
mptcyh 2010-06-08
  • 打赏
  • 举报
回复
是不是DLL没放在同一个目录下.
jason_28693 2009-04-13
  • 打赏
  • 举报
回复
把 stdcall 改成cdecl ,string 改成 phcar;
fengfan 2009-04-13
  • 打赏
  • 举报
回复
我觉得吧可以做一下尝试:

1.声明中的 string 改为PChar 试一下.
2.去掉stdcall .
3.调用的时候不要使用'aaa' 而是使用变量传递.

写Dll返回String这种方式尽量避免使用.应该使用 参数传出结果最好.
yc_8301 2009-04-13
  • 打赏
  • 举报
回复
dll是不是VC或非Delphi写的呀。。
如果不是Delphi写的dll,请注意 调用约定和dll中函数名的问题。。由于编译器不同,形成dll的函数名还是不同的。。
可以使用微软的 Depends 查看一下函数名,之后在调用
kjiwu 2009-04-13
  • 打赏
  • 举报
回复
dll有源码不?
给我传个,我也试试!kjiwu_001@sina.com
cycttt 2009-04-11
  • 打赏
  • 举报
回复
帮顶一个
w20011025 2009-04-10
  • 打赏
  • 举报
回复
DING
AlexChan1981 2009-04-10
  • 打赏
  • 举报
回复
现在不知道还有多少人在用BCB,我用过两年,
你的问题应该不是DLL的问题,建议你断点调试,看具体是哪段代码有问题
willsmith 2009-04-09
  • 打赏
  • 举报
回复
up
xiaoxiao_8 2009-04-08
  • 打赏
  • 举报
回复
兄弟,你给我的Longin.dll文件装载不了。
xiaoxiao_8 2009-04-08
  • 打赏
  • 举报
回复
兄弟,你给我的Longin.dll文件装载不了。
qdlgx 2009-04-08
  • 打赏
  • 举报
回复
不用看了很简单,你的
Function EnPassWord(PwdValue: String): String;stdcall;external 'Login.dll';
这句话路径不明确,你的这个工程与Login.dll肯定不在同一目录下,你把他们放在一个文件夹下,或者加上详细的路径名字。
jakefj 2009-04-08
  • 打赏
  • 举报
回复
To xiaoxiao_8:
我已经传给你了。
liangpei2008 2009-04-07
  • 打赏
  • 举报
回复

ShareMem must be the
first unit in your library's USES clause AND your project's




program Project1;

uses
ShareMem,
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

starluck 2009-04-07
  • 打赏
  • 举报
回复


unit Unit1;

interface

uses
ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi, ShlObj;




放到最前面。
DLL中也是。 不過你最好把DLL的單元也拿上來看下。
jakefj 2009-04-07
  • 打赏
  • 举报
回复
引用ShareMem单元了,运行时还是报write address '00XX...'出错
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi, ShlObj,ShareMem;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public

{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
Function EnPassWord(PwdValue: String): String;stdcall;external 'Login.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
sPwdValue: String;
begin
sPwdValue := EnPassWord('AAA');
//showmessage(sPwdValue);
end;

end.
js0001 2009-04-07
  • 打赏
  • 举报
回复
当在动态链接库中使用了长字符串类型作为函数的参数、变量或返回值时要应用ShareMem单元,而且必须是第一个被引用的单元。
jakefj 2009-04-07
  • 打赏
  • 举报
回复
报写的地址出错.因为我没有调用过Dll,所以也不知道是哪出问题了.
starluck 2009-04-07
  • 打赏
  • 举报
回复


報什麼錯呢?

如果返回是 參數是 String 類型,最好調用者與DLL中都帶上 shareMem 單元,
具體你看下生成DLL的說明。
僵哥 2009-04-07
  • 打赏
  • 举报
回复
请使用ShareMem
加载更多回复(9)

830

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧