DLL 没用string 怎么还提示delphi invalid pointer operation

fscnt fscnt 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
//调用程序
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;
begin

end.
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
fscnt
Delphi 5,945 成员 262,941 内容