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