Write TAPI applications

xiaoxiao2021-03-06  42

TAPI (Telphony Application Programming Interface) can be referred to as a telephone program interface, which is a programmed interface of Microsoft's computer and telephone network, so that the programmer can use this interface to use a variety of computer complicated communication through the telephone line. The features that TAPI can provide for automatic dialing; file, fax, email, files, access to Internet, or other form information services, organize conference calls, use the call identification to process the call, the computer lines passing through the telephone line cooperation. Some of the features mentioned here have long been widely used, and some are very small for this type of function without providing such functions. Here, the author does not want to discuss how the TAPI can achieve more and more, just talk about the program.

Promote the author's use of TAPI writing programs mainly due to the need to send faxes in the work, and each fax needs to confirm that if the phone is the least function, it takes a lot of time every time. If you have anyone in your confirmation, then you will come again, the efficiency is lower. Therefore, the author thinks that using TAPI to write a program to automatically dial using modem. After the call is completed, record the content, save every time you look hard, watch the number dial. The program is shared with the reader below.

The author uses Delphi as a development tool because the reason is that the Delphi development program is convenient and fast, and the use of the database is relatively simple. Friends who have used Visual C know that it is very detailed. Many of the programs developed by the author refer to Win32 SDK help, especially when writing TAPI programs, carefully studied the TAPI part. Write a TAPI program using the VC to use the ready-made "TAPI.H" header file, but use Delphi to translate the C version of the header file into the Object Pascal, and then reference the function in "Tapi32.dll" to the header file. . Fortunately, this job does not need us to do, from the Inprise site, you can get Delphi's header files about TAPI programming, save a lot of things, the author's header file TAPI.PAS is written by Davide Moretti, if needed, friends can pass the newspaper Contact the author.

First introduce several functions used in the program: LineInitialize, LinenegotiateApiversion, LineOpen, Linemakecall, Linehandoff, LineShutdown, LineconfigDialog, LineCallbackProc, Linegeticon. The function of the function is: LineInitialize initialization line, LinenegotiateApiversion determines the TAPI version number, LineOpen open line, lineconfigDialog display line device properties, linemakecall automatically dials the phone number.

Linegeticon gets the handle of the line device icon, linehandoff transfer the Modem control line right to the user, lineshutdown shuts down the line. The function name used here is the same as the function name output in TAPI32.DLL.

Due to the difference in type definitions in Delphi and VC, the author is necessary to illustrate the difference between the function defined in VC and Delphi. Take LineInitialize as an example, defined in VC as

Long LineInitialize (LPHlineApp LPhlineApp, Hinstance Hinstance, LineCallback Lpfncallback, LPCSTR LPSZAPPNAME, LPDWORD LPDWNUMDEVS). lphlineApp is the handle pointer of the line TAPI application. Hinstance is an instance pointer, and lpfncallback points to the call return processing function, LPSZAPNAME points to the application name string provided by the user, and LPDWNumDevs points to the number of line devices available. The definition of this function in the Delphi file TAPI.PAS is as follows: Function LineInitialize (Var lphlineApp: thlineApp; Hinstance: hinst;

LPFNCALLBACK: TLINECALLBACK;

LPSZAPPNAME: PCHAR; VAR LPDWNUMDEVS: longint;

Where we define thrineapp, TLINECALLBACK is a pointer to Longint (& longInt). The definition of other functions is pushing, replacing the corresponding type in Delphi, if it is a long pointer, such as the handle pointer, can be defined with "& longint".

The following describes the code part of the program, where the author assumes the reader to have the Delphi database and the general programming basis. First, two Paradox7 tables are built with Database Desktop, which are "Workphone.db" and "Friendphone.db". Place TTABLE, TDATASOURCE, TDBGRID, and TPOPUPMENU controls on the master Form. Program Definition SAPPDIR: String Saves the application where the application is located, set sappdir: = getCurrentdir. Define two processes in the pop-up menu to load two database tables in TDBGRID, respectively.

Procedure TMAINFORM.FRIENDPHONECLICK (Sender: TOBJECT);

Begin

Mainform.table1.act: = false;

Mainform.table1.tablename: = sappdir 'friendphone.db';

Mainform.caption: = 'Auto Dial - Friend Phone';

Mainform.table1.act: = true;

END;

Procedure Tmainform.SelectClassMateClick (Sender: TOBJECT);

Begin

Mainform.table1.act: = false;

Mainform.table1.tablename: = sappdir 'Workphone.db';

Mainform.caption: = 'Auto Dial - Work Call';

Mainform.table1.act: = true;

END;

Set DGEDITING in the TDBGRID's options attribute to True, allowing the user to directly modify the contents in the table. Define Dialphone and DeleteRecord in the pop-up menu to make a call number and delete the current record, respectively. The following mainly introduces the TAPI application part of the call. The phone number is passed by mainform.table1.fields.fields [0] .sstring as a string.

The implementation code is as follows, where the article will not be too long to save unnecessary error prompts and part of the code.

Variable definitions

Lineapp: thlineApp; // TAPI Application Handle

Line: thline; // Line handle

Call: thcall; // Call handle

Callparams: TLINECALLPARAMS; / / Call parameters

NDEVS, TAPIVERSION, ERRORCODE: Longint; // Line Equipment number, TAPI version number, error code EXTID: TLINEEXTENSIONID; // TAPI expansion version number

Lineicon: Hicon; // Line Equipment Icon

Process definition

Procedure LineCallback (HDevice, DWMSG, DWCallbackInstance,

DWPARAM1, DWPARAM2, DWPARAM3: Longint); // Asynchronous call return processing function

{$ IFDEF WIN32}

STDCALL;

{$ Else}

EXPORT;

{$ ENDIF}

VAR

Hcall: thcall;

Begin

IF dwmsg = line_reply then {linemakemake response result}

IF dwparam2 <0 THEN {call response error handling};

Else if dwmsg = line_callState Then {Call Status Information}

Begin

HCall: = thcall (hdevice); // Type conversion Thcall is longint type

Case dwparam1 of

LineCallState_Idle: {Call Invalid Processing}

IF HCALL <> 0 THEN

Begin

LinedeallocateCall (HCALL);

END;

LineCallState_Proceeding: {Call Normal Processing}

LINECALLSTATE_DIALTONE: {detected dialing}

LINECALLSTATE_DIALING: {is dialing}

LineCallState_disconnected: {Connection has been disconnected}

Begin {Disconnect Reason}

IF dwparam2 = linedisconnectMode_normal dam {normal disconnection}

Else if dwparam2 = linedisconnectmode_busy the {Line busy}

LineCallState_busy: {Line Busy Processing}

END;

END;

Procedure tdialform. (Dialnumber: String); // DialNumber is a phone number string

Begin

WITH CALLPARAMS DO {CallParams Type Reference VC definition, change DWORD to longint}

Begin

DWTOTALSIZE: = Sizeof (Callparams);

Dwbearermode: = linebearermode_voice; // bearer mode is voice

DWMEDiamode: = linemediamode_interactiv

Evoice; // Media mode is interactive voice

END;

IF LineInitialize (LineApp, Hinstance, Linecallback, NIL, NDEVS <0

Then // line cannot be initialized

Else

IF ndevs = 0 THEN / / No TAPI Line Equipment

Begin

LINESHUTDOWN (LINEAP);

Lineapp: = 0;

end

Else

IF Linenegotiateapance (LineApp, 0, $ 00010004, $ 00020000,

TapiVersion, EXTID) <0 // negotiation TAPI version number TAPI1.4 ~ TAPI2.0

THEN BEGIN {TAPI version is not compatible}

LINESHUTDOWN (LINEAP);

LineApp: = 0; END

Else

ErrorCode: = lineopen (lineApp, Linemapper, Line, Tapiversion, 0, 0,

LineCallPrivilege_none, LineMediamode_

InteractiveVoice, @ Callparams); // Open the line

If ErrorCode <0 THEN {line can't open}

Else

Begin {Line Open Success}

LineconfigDialog (0, self.handle, nil); // Show line device properties

Linegeticon (0, `TAPI / LINE`, LINEICON

// Lineicon is a line device icon handle, which can assign a value to Ticon.Handle

IF linemakecall (line, call, pchar (dialnumber), 0, @ callparams) <0 THEN {call failed}

Else

LineHandoff (Call, `Telephone Dial Program`, LineMediamode_interactiveVoice;

/ / Should trigger linehandoff in the program, transfer from TAPI control to manual control

END;

END;

The above code is somewhat mess because of the actual procedures, I believe that friends who have a lot of understanding of Delphi programming are easy to understand. The effect of this program is that a database table is first appeared. Use the right-click to open a communication recording file, right-click Select the dial-up pop-up dialog box to display the status of the line processing, prompting the user to pick up the earpiece after dialing. The entire process is similar to the telephone dialing program that comes with the system, but the TAPI method introduced by the author allows us to write more features and more friendly interfaces. In the future, the author will introduce TAPI programming, I hope to help friends who don't know TAPI when developing programs.

转载请注明原文地址:https://www.9cbs.com/read-78597.html

New Post(0)