Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | unit DemoMain; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
||
7 | Dialogs, StdCtrls, ExtCtrls; |
||
8 | |||
9 | type |
||
10 | TForm1 = class(TForm) |
||
11 | DeviceListBox: TListBox; |
||
12 | Label1: TLabel; |
||
13 | CallBtn: TButton; |
||
14 | PhoneNumberEdit: TEdit; |
||
15 | Label2: TLabel; |
||
16 | procedure FormShow(Sender: TObject); |
||
17 | procedure DeviceListBoxClick(Sender: TObject); |
||
18 | procedure CallBtnClick(Sender: TObject); |
||
19 | procedure PhoneNumberEditChange(Sender: TObject); |
||
20 | private |
||
21 | procedure ListDevices; |
||
22 | end; |
||
23 | |||
24 | var |
||
25 | Form1: TForm1; |
||
26 | |||
27 | implementation |
||
28 | |||
29 | {$R *.dfm} |
||
30 | |||
31 | function GetTapiDevices(buf: PAnsiChar): integer; stdcall; external 'MakeCall.dll'; |
||
32 | function MakeCall(phoneNumber: PAnsiChar; deviceId: integer): integer; stdcall; external 'MakeCall.dll'; |
||
33 | |||
34 | type |
||
35 | TAnsiCharArray = array of AnsiChar; |
||
36 | |||
37 | function ArrayToString(const a: TAnsiCharArray): string; |
||
38 | begin |
||
39 | if Length(a)>0 then |
||
40 | SetString(Result, PChar(@a[0]), Length(a)) |
||
41 | else |
||
42 | Result := ''; |
||
43 | end; |
||
44 | |||
45 | procedure TForm1.CallBtnClick(Sender: TObject); |
||
46 | var |
||
47 | s: AnsiString; |
||
48 | begin |
||
49 | s := PhoneNumberEdit.Text; |
||
50 | MakeCall(PAnsiChar(s), DeviceListBox.ItemIndex); |
||
51 | end; |
||
52 | |||
53 | procedure TForm1.FormShow(Sender: TObject); |
||
54 | begin |
||
55 | ListDevices; |
||
56 | end; |
||
57 | |||
58 | procedure TForm1.DeviceListBoxClick(Sender: TObject); |
||
59 | begin |
||
60 | CallBtn.Enabled := (DeviceListBox.ItemIndex <> -1) and (PhoneNumberEdit.Text <> ''); |
||
61 | end; |
||
62 | |||
63 | procedure TForm1.PhoneNumberEditChange(Sender: TObject); |
||
64 | begin |
||
65 | CallBtn.Enabled := (DeviceListBox.ItemIndex <> -1) and (PhoneNumberEdit.Text <> ''); |
||
66 | end; |
||
67 | |||
68 | procedure TForm1.ListDevices; |
||
69 | var |
||
70 | len: integer; |
||
71 | buf: TAnsiCharArray; |
||
72 | begin |
||
73 | len := GetTapiDevices(nil); |
||
74 | SetLength(buf, len+1); |
||
75 | GetTapiDevices(PAnsiChar(buf)); |
||
76 | DeviceListBox.Items.Text := ArrayToString(buf); |
||
77 | end; |
||
78 | |||
79 | end. |