Modified demand program based on Win95 TAPI

zhaozj2021-02-11  202

Author: Tan Anping

----

First, the introduction:

---- With the popularity of Win95 operating systems, communication between computers has become the requirements of most application development, which is that Win95 can support most hardware, but also provide convenience for hardware operations. The communication means provided by the programming interface (API), WIN95 application interface (API) is roughly divided into the following categories: 1 WINSOCK API based on TCP / IP protocols, microcomputer communication on the LAN or the Internet can be implemented; Technologies: Dynamic Data Exchange (D D E); 3 Based on Direct Cable Connection Communication Technology, you can directly operate serial port, parallel port, and far infrared interface; 4 Communication application interface based on telephone lines (T A P I / Telephony API, convenient to modem; from the current development status, modem has become an important tool for long-distance communications. Together, Microsoft and Intel have developed a programming interface such as TAPI, and Blight segments prepared using the API function are applicable to the Borland C compiler, and can also insert compilation operation in the Visual C program, as Win95 application staff, learn to use TAPI programming operation modem via telephone line to communicate this technology is very Necessary. Apply the TAPI programming in the next face:

Second, the communication process

---- 1 Initialization Line (Communication Borders should be the initialization line)

---- By using the LineInitialize function to initialize TAPI.dll to get TAPI's pointer HTAPI using the handle, pay attention to the definition of the callback function in the parameter (all the functions of all functions can be helpful from BC 5.0 and Visual C 5.0. Get it); Get the line handle HLINE by calling the LineOpen function (with parameters HTAPI); reuse the LinegetID (with parameter hline) to get the modem handle HMODEM

---- 2 Distribution line (optional)

----

---- Adjustment of setcommconfig (use hmodem) to change the settings of the modulator

---- 3 Dial (executed by the call)

---- Use the linemakecall function (with HLINE) to dial, after completion, get the call handle Hcall (call party's call handle) ---- 4 answering link (by the called party)

---- When the called back-up function gets linecallState_offering message, call the Lineanswer function to realize the automatic answer (the call handle HCALL is given by the parameter of the back function)

---- 5 Durable Communications (Double Party)

---- When the recovery function receives linecallState_connected, please clear the inclination buffer, you can use the function to use the function to use the function for the writefile and readfile function to the data exchange, and note the parameter hfile is the modulator handle HMODEM

---- 6 hang up (some side)

---- Communication completion, all of them can stop calls with the function linedrop (hcall, null, 0). This function also sends a LineCallState_Idle message to the back function.

---- 7 Closed Line (Double Party)

---- Communication two callback functions should call the function literalLocateCall (HCall) to release the resources occupied by the corresponding call when receiving the LineCallState_Idle message; use lineclose (hline) to release resources by LineOpen when the callback function receives the LineCallState_Disconnected message. Calling LINESHUTDOWN (HTAPI) Release the resource allocated for line devices

Third, hard and hard work

---- The figure shows the location of our application and the hardware and hardware circles involved in it:

---- Our communication app is operated by TAPI operation Modem dial, answering, link, hang-up control phone call, when developing DOS applications, we often use Hayes-compatible AT command set to complete these operations, due to modem manufacturers For this command set, our DOS application can generally only operate a small part of the modem, and each manufacturer provides a Windows driver, so using TAPI-based applications can operate most modems The communication API in the figure is a programming interface that the application is transmitted and receives data.

Fourth, the block diagram of the program flow

---- Since Win95 is a multi-task operating system, our flowchart can only represent the execution of this application, the wait and detection in the program is actually waiting for the Win95, so it does not occupy the CPU time, It can be seen in the following program. In addition, the agreement of data exchange can be customized, and the existing agreement can be used.

V. Software Conditioning ---- Based on the framework of Windows programming, we only introduce a sub-source program involving the communication:

---- 1 item should be included in the document:

---- #include

---- Please note that the properties of the works should be the Windows 32-bit application program

---- 2 All-game variables and types of allocation involved in the communication:

Char Recbuf [20], BUF [20] / / buffer zone

DWORD Error; // Failure error

COMSTAT STATUS; // State code

DWORD NUMLINE; / / Line setup number

LineCallParams Para; / / Call parameters

TMYDECFRAME * PWIN = NULL; // Main window pointer

HlineApp myhtapi; // Line Road Application Code Handle

Hline myhline; // line handle

Handle myhmodem; // modulator handle

Hcall myhcall; // Call handle

Typedef struct tagmodemid {

Handle Hmodem;

Char modemname [1];

} Modemid;

--- 3 Function definition below to get the modulated demander handle

---- Because each modem is a sign string length, the function is used in a variable length string, and the processing method is to assign a SizeOf (Varstring) size of the SIZEOF (Varstring) size first, and then use the space to accommodate When you call LineGetID, the information returned by Windows, determines that the required space size is reassigned according to the return information, and then call the LineGetID again to get a complete logo string.

Void gethmodem (Hline Hline)

{MODEMID FAR * MID;

Varstring * STR;

Long LID;

DWORD size;

CHAR MARK = 1;

Str = (varstring *) malloc (sizeof (varstring));

IF (! STR)

Return NULL;

Str-> dwtotalsize = sizeof (varstring);

DO

{IF (LinegetId (Myhline, 0, Null, LineCallselect_Line, Str,

"Comm / DataMode") == 0) && (STR-> DWTOTALSIZE

dwneededsize))))

{dwsize = str-> dwneededsize;

Free (STR);

Str = (Varstring *) Malloc (dwsize);

IF (! STR)

{MyHmodem = NULL;

Mark = 2;

}

Str-> dwtotalsize = dwsize;

}

ELSE MARK = 0;

} while (mark == 1);

IF (Mark == 0)

{MID = (MODEMID FAR *) ((LPSTR) STR STR-> DWSTRINGOFFSET;

Myhmodem = mid-> hmodem;

}

Free (STR);

}

---- 4 In the initialization function of the main window, add the initialization process of the line: PWIN = this; // Won the main window pointer

While (LineInitialize (& myhtapi, getModule () -> getInstance (),

(LINECALLBACK) MakeProcinstance (FarProc) lpfncallback,

GetModule () -> getInstance ()), "tryerr_reinit) == lineERR_REINIT

{SLEEP (1); // delay};

Error = lineopen (htapi, 0, & hline, 0x10004, 0, 0, linecallprivilege_monitor

LineCallPrivilege_owner, linemediamode_datamodem, null;

IF (Error! = 0)

{Sprintf (buf, "% lx", error);

Messagebox (buf, 0, mb_ok);

Else

{Gethmodem (myhline); // Take the value of MyHMODEM

IF (MyHMode! = NULL)

{Para.dwbearermode = linebearermode_voice;

Para.dwmediamode = linemediamode_datamode;

Para.dwtotalsize = SizeOf (LineCallParams);

Error = linemakecall (myhline, & myhcall, "8880751", 0, ¶);

IF (Error! = 0)

{Sprintf (buf, "% lx", error);

Messagebox (buf, 0, mb_ok);

}

}

}

---- 5 Fixing Function of 5 callback

Void Far Pascal Tmydecframe :: lpfncallback

(DWORD HDEVICE, DWORD DWMSG,

DWORD DWCALLBACKINSTANCE,

DWORD DWPARAM1, DWORD DWPARAM2,

DWORD dwparam3) //

Parameter defines the parameter definitions in the lineCallbackFunc function

{INT REC_NUM = 0;

Switch (dwparam1)

{CASE LINECALLSTATE_CONNECTED:

DWORD LEN;

Clearcommerror (MyHModem, & Error, & status);

REC_NUM = status.cbinque;

Readfile (MyHMODEM, RECBUF, REC_NUM, & LEN, 0);

/ / It has been prepared for data communication to data communication, which can set a sign

Writefile (MyHModem, "Success", 7, & len, 0);

Readfile (MyHMODEM, RECBUF, 8, & LEN, 0);

PWIN-> MessageBox (RECBUF, 0, MB_OK);

Break;

Case LineCallState_Idle:

LinedeallocateCall (MyHCALL);

Break;

Case LineCallState_disconnected:

Lineclose (Myhline);

LINESHUTDOWN (MyHTAPI);

Break;

}

}

---- 6 Definition of the called party

Void Far Pascal Tmydecframe :: lpfncallback (DWORD HDEvice, DWORD DWMSG, DWORD DWCALLBACKINSTANCE, DWORD DWPARAM1, DWORD DWPARAM2,

DWORD dwparam3)

{INT REC_NUM = 0;

Switch (dwparam3)

{CASE LINECALLPRIVILE_OWNER:

Myhcall = (hcall) HDEvice;

Break;

} // Only a caller with a private privilege to call, you will answer the call.

Call handle here

Switch (dwparam1)

{CASE LINECALLSTATE_CONNECTED:

DWORD LEN;

Clearcommerror (MyHModem, & Error, & status);

REC_NUM = coms.cbinque;

Readfile (MyHMODEM, RECBUF, REC_NUM, & LEN, 0); // Remove the pickup buffer area

Readfile (MyHMODEM, RECBUF, 7, & LEN, 0);

Writefile (MyHModem, "Received", 8, & len, 0);

PWIN-> MessageBox (RECBUF, 0, MB_OK);

Break;

Case LineCallste_offering:

Lineanswer (MyHCall, NULL, 0);

Break; // End a self-active answer

Case LineCallState_Idle:

LinedeallocateCall (MyHCALL);

Break;

Case LineCallState_disconnected:

Lineclose (Myhline);

LINESHUTDOWN (MyHTAPI);

Break;

}

}

Sixth, rehabilitation

---- Used in the above program is synchronous read and write mode, as long as Writefile or ReadFile does not complete the specified I / O task, they will not return the process, in many cases, this is an incredible CPU time waste The improvement method is to use the ClearcomMerror function to determine how many bytes in the serial port buffer in the serial port buffer in each time read, and the write mode should be used as a asynchronous mode, first, one Overlapped structure, from BC The structure obtained in 5.0 is defined as follows:

Typedef struct _overlapped {// o

DWORD INTERNAL

DWORD INTERNALH;

DWORD OFFSET;

DWORD OFFSETHIGH;

Handle HEVENT;

Overlapped;

---- We define overlapped myovlp;

---- We only use the HEVENT members, other members are set; HEVENT is set to CreateEvent (NULL, TRUE, FALSE, NULL) event handle; then call Writefile (MyHModem, "Received", 8, & len, & myovlp;

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

New Post(0)