Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | library MakeCall; |
2 | |||
3 | uses |
||
4 | SysUtils, |
||
5 | daniel-mar | 5 | AnsiStrings, |
6 | hbTAPI, |
||
7 | dialogs; |
||
2 | daniel-mar | 8 | |
9 | {$R *.res} |
||
10 | |||
5 | daniel-mar | 11 | function GetTapiDevicesA(buf: PAnsiChar): integer; stdcall; |
2 | daniel-mar | 12 | var |
5 | daniel-mar | 13 | mTapiLine: ThbTapiLine; |
2 | daniel-mar | 14 | len: Integer; |
5 | daniel-mar | 15 | s: AnsiString; |
2 | daniel-mar | 16 | begin |
5 | daniel-mar | 17 | mTapiLine := ThbTapiLine.Create(nil); |
2 | daniel-mar | 18 | try |
19 | try |
||
20 | mTapiLine.Active := false; |
||
5 | daniel-mar | 21 | s := AnsiString(mTapiLine.DeviceList.Text); |
22 | len := (Length(s)+1{NUL}) * SizeOf(AnsiChar); |
||
2 | daniel-mar | 23 | if buf <> nil then |
24 | begin |
||
5 | daniel-mar | 25 | FillChar(buf^, len, 0); |
26 | AnsiStrings.StrPCopy(buf, s); |
||
27 | end; |
||
28 | result := len; |
||
29 | except |
||
30 | result := -1; |
||
31 | end; |
||
32 | finally |
||
33 | FreeAndNil(mTapiLine); |
||
34 | end; |
||
35 | end; |
||
36 | |||
37 | function GetTapiDevicesW(buf: PWideChar): integer; stdcall; |
||
38 | var |
||
39 | mTapiLine: ThbTapiLine; |
||
40 | len: Integer; |
||
41 | s: WideString; |
||
42 | begin |
||
43 | mTapiLine := ThbTapiLine.Create(nil); |
||
44 | try |
||
45 | try |
||
46 | mTapiLine.Active := false; |
||
47 | s := WideString(mTapiLine.DeviceList.Text); |
||
48 | len := (Length(s)+1{NUL}) * SizeOf(WideChar); |
||
49 | if buf <> nil then |
||
50 | begin |
||
51 | FillChar(buf^, len, 0); |
||
2 | daniel-mar | 52 | StrPCopy(buf, s); |
53 | end; |
||
5 | daniel-mar | 54 | result := len; |
2 | daniel-mar | 55 | except |
56 | result := -1; |
||
57 | end; |
||
58 | finally |
||
59 | FreeAndNil(mTapiLine); |
||
60 | end; |
||
61 | end; |
||
62 | |||
5 | daniel-mar | 63 | function MakeCallA(phoneNumber: PAnsiChar; deviceId: integer): integer; stdcall; |
2 | daniel-mar | 64 | var |
5 | daniel-mar | 65 | mTapiLine: ThbTapiLine; |
66 | sPhoneNumber: AnsiString; |
||
2 | daniel-mar | 67 | begin |
5 | daniel-mar | 68 | mTapiLine := ThbTapiLine.Create(nil); |
2 | daniel-mar | 69 | try |
70 | mTapiLine.Active := false; |
||
71 | mTapiLine.CallParams.Flags := 0; |
||
72 | mTapiLine.DeviceID := deviceId; |
||
73 | mTapiLine.Active := true; |
||
74 | if not mTapiLine.Active then |
||
75 | begin |
||
76 | // Usually "TAPI device not available" |
||
77 | result := -1; |
||
78 | exit; |
||
79 | end; |
||
80 | try |
||
5 | daniel-mar | 81 | sPhoneNumber := phoneNumber; |
82 | mTapiLine.MakeCall(String(sPhoneNumber)); |
||
2 | daniel-mar | 83 | except |
84 | // This can tappen when the headset is active, so the line is busy |
||
85 | result := -2; |
||
86 | exit; |
||
87 | end; |
||
88 | result := 0; |
||
89 | finally |
||
90 | FreeAndNil(mTapiLine); |
||
91 | end; |
||
92 | end; |
||
93 | |||
5 | daniel-mar | 94 | {$IFDEF UNICODE} |
95 | function MakeCallW(phoneNumber: PWideChar; deviceId: integer): integer; stdcall; |
||
96 | var |
||
97 | mTapiLine: ThbTapiLine; |
||
98 | sPhoneNumber: WideString; |
||
99 | begin |
||
100 | mTapiLine := ThbTapiLine.Create(nil); |
||
101 | try |
||
102 | mTapiLine.Active := false; |
||
103 | mTapiLine.CallParams.Flags := 0; |
||
104 | mTapiLine.DeviceID := deviceId; |
||
105 | mTapiLine.Active := true; |
||
106 | if not mTapiLine.Active then |
||
107 | begin |
||
108 | // Usually "TAPI device not available" |
||
109 | result := -1; |
||
110 | exit; |
||
111 | end; |
||
112 | try |
||
113 | sPhoneNumber := phoneNumber; |
||
114 | mTapiLine.MakeCall(String(sPhoneNumber)); |
||
115 | except |
||
116 | // This can tappen when the headset is active, so the line is busy |
||
117 | result := -2; |
||
118 | exit; |
||
119 | end; |
||
120 | result := 0; |
||
121 | finally |
||
122 | FreeAndNil(mTapiLine); |
||
123 | end; |
||
124 | end; |
||
125 | {$ELSE} |
||
126 | function MakeCallW(phoneNumber: PWideChar; deviceId: integer): integer; stdcall; |
||
127 | var |
||
128 | wst: WideString; |
||
129 | ast: AnsiString; |
||
130 | begin |
||
131 | wst := WideString(phoneNumber); |
||
132 | ast := AnsiString(wst); |
||
133 | result := MakeCallA(PAnsiChar(ast), deviceId); |
||
134 | end; |
||
135 | {$ENDIF} |
||
136 | |||
2 | daniel-mar | 137 | exports |
5 | daniel-mar | 138 | MakeCallA, |
139 | MakeCallW, |
||
140 | GetTapiDevicesA, |
||
141 | GetTapiDevicesW; |
||
2 | daniel-mar | 142 | |
143 | begin |
||
144 | end. |