我的dll:library bcpnt;
uses
SysUtils,Dialogs, Classes;{$R *.res}function GetString(i:integer) : string ;stdcall;
beginGetString := 'Hello from the DLL!' ;end ;procedure showmess; stdcall;
begin showmessage('你好');
end;exportsGetString,
showmess;
begin
end.
--------------------------------------------------------------------------
我的dll调用程序:
unit usepas;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tmain = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
main: Tmain;implementation{$R *.dfm}
function GetString(i:integer) : string ; stdcall; external 'bcpnt.dll'; name 'GetString' ;
procedure showmess ;stdcall; external 'bcpnt.dll' ;
procedure Tmain.Button1Click(Sender: TObject);
begin
showmessage( pchar(GetString(1)) ) ;end;procedure Tmain.Button2Click(Sender: TObject);
begin
showmess;
end;end.
调用showmess没问题,而在调用showmessage( pchar(GetString(1)) ) ;时第一次没问题第二次也能成功显示,但显示完后会弹出invalid pointer operation的错误
哪位官人小民一名 阿
uses
SysUtils,Dialogs, Classes;{$R *.res}function GetString(i:integer) : string ;stdcall;
beginGetString := 'Hello from the DLL!' ;end ;procedure showmess; stdcall;
begin showmessage('你好');
end;exportsGetString,
showmess;
begin
end.
--------------------------------------------------------------------------
我的dll调用程序:
unit usepas;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tmain = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
main: Tmain;implementation{$R *.dfm}
function GetString(i:integer) : string ; stdcall; external 'bcpnt.dll'; name 'GetString' ;
procedure showmess ;stdcall; external 'bcpnt.dll' ;
procedure Tmain.Button1Click(Sender: TObject);
begin
showmessage( pchar(GetString(1)) ) ;end;procedure Tmain.Button2Click(Sender: TObject);
begin
showmess;
end;end.
调用showmess没问题,而在调用showmessage( pchar(GetString(1)) ) ;时第一次没问题第二次也能成功显示,但显示完后会弹出invalid pointer operation的错误
哪位官人小民一名 阿
解决方案 »
- 很简单的个ADOQuery的问题
- 如何读取xml文件并显示成表格模式
- 请问各位,我在程序中OPEN一个TABLE控件之后,是否会把后台数据库对应的表给锁住,我想让我的程序同时在多个机器上运行?
- 如何将备注字段转换到Memo中去
- 初学者应该怎么学比较好?
- 怎样连接带密码的ACCESS数据库!(在线等待)
- 如何将一个表中的数据读入到另外一个表中对应的字段。
- 请问各位高手,怎样用delphi调用一个应用程序?
- 将VC++语句转成delphi语句
- delphi.csdn 代表大会,请大家互相通告
- 在Delphi中怎么通过ADO访问任意数据库如SQL Server,Oracle中的所有数据库名,选中一个数据库,然后得到这个数据库中的所有表名?
- 初学delphi,上来问个小问题!!!!还望各位多多帮助!
修改为
Result:='Hello from the DLL!' ;
看看
delphi的string是自动分配长度的,用dll时,坚决不要用string,可以用Pchar!!!