码农的笔记

Delphi虽好,但已不流行; 博客真好,可以做笔记

博客园 首页 新随笔 联系 订阅 管理

本人C++是个菜鸟,

C++编写的DLL,Delphi调用,先弄个简单的C++的DLL;

--------------------------------------

C++ 

 

 

 

 

 

 

 

 

 

 

 ------------------------------

Delphi:

-------------------Unit

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
PMyrecord=^Myrecord;
Myrecord=record
ss:array[0..9] of AnsiChar ;
ii:Integer ;
end;

PACS_ELEVATOR_SET=^ACS_ELEVATOR_SET;
ACS_ELEVATOR_SET=record
ForbidCardType:LongWord; // 禁止的卡片类型
StartTime1:array[0..8] of AnsiChar; // 起始时间1: 字符串, 8个字符, 格式 hh:mm:ss
EndTime1:array[0..8] of AnsiChar; // 结束时间1: 字符串, 8个字符, 格式 hh:mm:ss
StartTime2:array[0..8] of AnsiChar; // 起始时间2: 字符串, 8个字符, 格式 hh:mm:ss
EndTime2:array[0..8] of AnsiChar; // 结束时间2: 字符串, 8个字符, 格式 hh:mm:ss
cRFU1:array[0..99] of AnsiChar ; // 预留
cRFU2:array[0..99] of AnsiChar ; // 预留
iRFU1:LongWord; // 预留
iRFU2:LongWord; // 预留
iRFU3:LongWord; // 预留
iRFU4:LongWord; // 预留
end;
var
Form1: TForm1;

implementation
function Ass(Myc:Myrecord):Integer;stdcall;external 'MyC_FirstDLL.dll' name 'Test001';
function Bss(Myc:PMyrecord):Integer;stdcall;external 'MyC_FirstDLL.dll' name 'Test002';
function Css(Myc:ACS_ELEVATOR_SET):Integer;stdcall;external 'MyC_FirstDLL.dll' name 'Test003';
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
mys:Myrecord;
begin
mys.ss[0]:='A';
mys.ii:=10;
ShowMessage(IntToStr(Ass(mys)));

end;

procedure TForm1.Button2Click(Sender: TObject);

var
mys:Myrecord;
ss:string;
i:Integer;
begin
for i:=0 to 9 do
begin
mys.ss[i]:=Char($0);
end;
mys.ss[0]:='A';
mys.ii:=10;
ShowMessage(IntToStr(Bss(@mys)));
ShowMessage(AnsiString (mys.ss));

end;

procedure TForm1.Button3Click(Sender: TObject);
var
i:Integer;
sStartTime1,sEndTime1,sStartTime2,sEndTime2:string;
vpara:ACS_ELEVATOR_SET;
begin
sStartTime1:='12:12'+':00' ;
sEndTime1:='12:12'+':00' ;
sStartTime2:='12:12'+':00' ;
sEndTime2:='12:12'+':00' ;
vpara.ForbidCardType :=2;
for i:=0 to 8 do
begin
vpara.StartTime1[i]:=Char($0);
vpara.EndTime1[i]:=Char($0) ;
vpara.StartTime2[i]:=Char($0);
vpara.EndTime2[i]:=Char($0) ;
end;
for i:=0 to 7 do
begin
vpara.StartTime1[i]:=sStartTime1[i+1];
vpara.EndTime1[i]:=sEndTime1[i+1] ;
vpara.StartTime2[i]:=sStartTime2[i+1];
vpara.EndTime2[i]:=sEndTime2[i+1] ;
end;
ShowMessage(IntToStr(Css(vpara)));
end;

end.

 

------------Form

object Form1: TForm1
Left = 868
Top = 524
Width = 288
Height = 364
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 8
Top = 16
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 8
Top = 48
Width = 75
Height = 25
Caption = 'Button2'
TabOrder = 1
OnClick = Button2Click
end
object Button3: TButton
Left = 112
Top = 288
Width = 75
Height = 25
Caption = 'Button3'
TabOrder = 2
OnClick = Button3Click
end
end

 

posted on 2021-01-20 14:19  码农的笔记  阅读(330)  评论(0编辑  收藏  举报