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 initial 贰inenegotiateapiversion determine 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 will modem control line right Go to the user, LINESHUTDOWN turns off 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 the 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. Delphi function is defined as follows in this document tapi.pas: function lineInitialize (var lphLineApp: THLineApp; hInstance: HInst; lpfnCallback: TLineCallback; lpszAppName: PChar; var lpdwNumDevs: Longint): Longint; where we define THLineApp, TLineCallback to point LONGINT's pointer (& 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.Active: = False; MainForm.Table1.TableName: = sAppDir 'friendphone.db'; MainForm.Caption: = 'automatic dialing - telephone friend'; MainForm. Table1.Active: = True; end; procedure TMainForm.selectclassmateClick (Sender: TObject); begin MainForm.Table1.Active: = False; MainForm.Table1.TableName: = sAppDir 'workphone.db'; MainForm.Caption: = 'automatic Dial - Workphone '; mainform.table1.active: = true; end; set DGEDITI in TDBGRID to True, allowing users 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 definition lineApp: thlineApp; // TAPI App Handle Line: Thline; // Call Handle Call: THCALL; // Call Handle CallParams: TLINECALLPARAMS; // Call Parameters NDEVS, TAPIVERSION, ERRORCODE: Longint; // Line Equipment Number, TAPI Version number, error code EXTID: TLINEEXTENSIONID; // TAPI extended version number lineicon: Hicon; // Line device icon process definition Procedure LineCallback (HDevice, DWMSG, DWCALLBACKISTANCE, DWPARAM1, DWPARLBACKINSTANCE, DWPARAM1, DWPARAM2, DWPARAM3: Longint); // Asynchronous call return processing Function {$ IFDEF WIN32} stdcall; {$ ELSE} EXPORT; {$ ENDIF} var Hcall: thcall; begin if dwmsg = line_reply the {linemakecall Response result} if dwparam2 <0 THEN {Call Response Error Processing}; ELSE IF DWMSG = LINE_CALLSTATE then {call status information} begin hCall: = THCall (hDevice); // THCall cast to type LongInt case dwParam1 of LINECALLSTATE_IDLE: {invalid call handling} if hcall <> 0 then begin lineDeallocateCall (hCall); end; LINECALLSTATE_PROCEEDING : normal call handling {} LINECALLSTATE_DIALTONE: {detected dial tone} LINECALLSTATE_DIALING: {dialing} LINECALLSTATE_DISCONNECTED: {} begin {disconnected disconnection cause} if dwParam2 = LINEDISCONNECTMODE_NORMAL then {} else if d normally open wParam2 = LINEDISCONNECTMODE_BUSY then {Busy} LINECALLSTATE_BUSY: {processing line is busy} end; end; procedure TDialForm (dialnumber: string);. // dialnumber telephone number string to begin with CallParams do {CallParams reference defines the type of VC, the DWORD to LongInt} begin dwTotalSize: = sizeof (CallParams); dwBearerMode: = LINEBEARERMODE_VOICE; // bearer mode is the voice dwMediaMode: = LINEMEDIAMODE_INTERACTIV EVOICE; // media interactive voice mode end; if lineInitialize (lineApp, hInstance, lineCallBack , NIL, NDEVS <0 THEN / / Line Incorrectization Processing ELSE IF NDEVS = 0 THEN / / None TAPI Line Apparatus Begin LineShutdown (LineApp); lineApp: = 0;