//调用程序
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TStrArr = array of Pchar;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
type
TDllReadCard = function(): TStrArr; stdcall;
var
DllReadCard: TDllReadCard;
DLLHandle: THandle;
sStrArr: TStrArr;
begin
SetLength(sStrArr, 10);
DLLHandle := LoadLibrary('Project2.dll');
if DLLHandle <= 0 then
raise Exception.Create('加载Project2.dll失败!');
@DllReadCard := GetProcAddress(DLLHandle, 'FDLL');
if not (@DllReadCard = nil) then
begin
sStrArr := DLLReadCard();
end;
edit1.Text := sStrArr[2];
end;
end.
dll程序
library Project2;uses
SysUtils,
Classes;
type
TStrArr = array of Pchar;{$R *.res}function FDLL(): TStrArr; stdcall;
var
sResult: TStrArr;
begin
SetLength(sResult, 10);
sResult[1] := Pchar('是');
sResult[2] := Pchar('否');
Result := sResult;
end;exports
FDLL;
beginend.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TStrArr = array of Pchar;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
type
TDllReadCard = function(): TStrArr; stdcall;
var
DllReadCard: TDllReadCard;
DLLHandle: THandle;
sStrArr: TStrArr;
begin
SetLength(sStrArr, 10);
DLLHandle := LoadLibrary('Project2.dll');
if DLLHandle <= 0 then
raise Exception.Create('加载Project2.dll失败!');
@DllReadCard := GetProcAddress(DLLHandle, 'FDLL');
if not (@DllReadCard = nil) then
begin
sStrArr := DLLReadCard();
end;
edit1.Text := sStrArr[2];
end;
end.
dll程序
library Project2;uses
SysUtils,
Classes;
type
TStrArr = array of Pchar;{$R *.res}function FDLL(): TStrArr; stdcall;
var
sResult: TStrArr;
begin
SetLength(sResult, 10);
sResult[1] := Pchar('是');
sResult[2] := Pchar('否');
Result := sResult;
end;exports
FDLL;
beginend.
解决方案 »
- StringGrid某行高亮显示
- idFTP如何在不同的目录下GET文件呢
- 如果TFrom(或TImage)上用鼠标选一个区域,拉的时候出现虚框??
- 在画布上画一个规则的多边形,并填充颜色,怎么实现??
- 求助?关于票据打印?
- constructor TDanHint.Create(AOwner:TComponent);//(AOwner:TComponent);代表什么
- 请问各位大侠,在我Import Active Media Player后,在使用时,如果我把DisplaySize设置成为mpFullScreen,怎样才能在全屏状态下响应鼠标
- 捕获窗体的最小化消息
- 驱动级ie插件找人写
- 谁能告诉我UTF8的格式?好像有位叫江雪(rivsnow)知道。
- 庆祝阿发伯BLOG访问量突破100000,散分(二)
- ServerSocket心跳包检测socket链路中断问题
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;
TStrArr = array of Pchar;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
type
TDllReadCard = procedure(var StrAyy: TStrArr); stdcall;
var
DllReadCard: TDllReadCard;
DLLHandle: THandle;
sStrArr: TStrArr;
begin
DLLHandle := LoadLibrary('Project2.dll');
if DLLHandle <= 0 then
raise Exception.Create('加载Project2.dll失败!');
@DllReadCard := GetProcAddress(DLLHandle, 'FDLL');
SetLength(sStrArr, 10);
if not (@DllReadCard = nil) then
begin
DLLReadCard(sStrArr);
end;
Caption := sStrArr[2];
end;
end.
library Project2;{ 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;type
TStrArr = array of Pchar; {$R *.res} procedure FDLL(var AStrArr: TStrArr); stdcall;
var
sResult: TStrArr;
n, nlength: Integer;
begin
nlength := length(AStrArr);
for n := 0 to nlength - 1 do
begin
if n = 1 then
AStrArr[n] := Pchar('是');
if n = 2 then
AStrArr[n] := Pchar('否');
end;
end;exports
FDLL;
begin end.
要不你就用静态数组