Subversion Repositories calllib

Rev

Rev 2 | Details | Compare with Previous | 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
 
5 daniel-mar 31
const
32
  {$IFDEF WIN64}
33
  makecalldll = 'MakeCall.64.dll';
34
  {$ELSE}
35
  makecalldll = 'MakeCall.32.dll';
36
  {$ENDIF}
2 daniel-mar 37
 
5 daniel-mar 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}
42
function GetTapiDevices(buf: PAnsiChar): integer; stdcall; external makecalldll name 'GetTapiDevicesA';
43
function MakeCall(phoneNumber: PAnsiChar; deviceId: integer): integer; stdcall; external makecalldll name 'MakeCallA';
44
{$ENDIF}
2 daniel-mar 45
 
5 daniel-mar 46
 
47
function ArrayToString(const a: TCharArray): string;
2 daniel-mar 48
begin
49
  if Length(a)>0 then
50
    SetString(Result, PChar(@a[0]), Length(a))
51
  else
52
    Result := '';
53
end;
54
 
55
procedure TForm1.CallBtnClick(Sender: TObject);
56
var
5 daniel-mar 57
  s: String;
2 daniel-mar 58
begin
59
  s := PhoneNumberEdit.Text;
5 daniel-mar 60
  MakeCall(PChar(s), DeviceListBox.ItemIndex);
2 daniel-mar 61
end;
62
 
63
procedure TForm1.FormShow(Sender: TObject);
64
begin
65
  ListDevices;
66
end;
67
 
68
procedure TForm1.DeviceListBoxClick(Sender: TObject);
69
begin
70
  CallBtn.Enabled := (DeviceListBox.ItemIndex <> -1) and (PhoneNumberEdit.Text <> '');
71
end;
72
 
73
procedure TForm1.PhoneNumberEditChange(Sender: TObject);
74
begin
75
  CallBtn.Enabled := (DeviceListBox.ItemIndex <> -1) and (PhoneNumberEdit.Text <> '');
76
end;
77
 
78
procedure TForm1.ListDevices;
79
var
80
  len: integer;
5 daniel-mar 81
  buf: TCharArray;
2 daniel-mar 82
begin
83
  len := GetTapiDevices(nil);
84
  SetLength(buf, len+1);
5 daniel-mar 85
  GetTapiDevices(PChar(buf));
2 daniel-mar 86
  DeviceListBox.Items.Text := ArrayToString(buf);
87
end;
88
 
89
end.