关于在VC6.0中用TAPI实现调制解调器通信的问题(各位高人救命)
关于在VC6.0中用TAPI实现调制解调器通信的问题:
在VC6.0用TAPI实现调制解调器通信时,在调用LineInitialize函数进行线路初始化时使用了回调函数lineCallbackFunc,并根据回调函数的返回值来检测线路连接状况,经拨后号在呼叫方产生“LINECALLSTATE_CONNECTED”信号表示线路连接正常,在被叫方得到消息LINECALLSTATE_OFFERING后调用应答函数Error=lineAnswer(myhCall,NULL,0)产生应答信号,且函数调用成功(返回值为正数)。但在被叫方回调函数未产生“LINECALLSTATE_CONNECTED”信号,且同时呼叫方写数据函数出错,错误代码为87(The parameter is incorrect)。不知究竟错误出在何处?为何被叫方没有产生“LINECALLSTATE_CONNECTED”信号,且呼叫方写数据出错?望各位老师给以指点。谢谢!(其中通信用两台计算机分别采用NT 4.0 workstation和Win98(第二版)操作系统,拨号和应答前均未进行线路配置,调制解调器均采用115200bps.)
其中主要TAPI函数调用如下:(其中myhTapi,myhLine,myhModem返回均为有效值)
==========================================================================================================
//初始化线路函数
void InitLine(int Direct)
{ //initialize the line
LINECALLBACK CallBackFun;
if(Direct==0)
CallBackFun=(LINECALLBACK)lineCallbackProc0; //调用呼叫放回调函数
else
CallBackFun=(LINECALLBACK)lineCallbackProc1; //调用被叫方回调函数
while((Error=lineInitialize(&myhTapi,g_hInst,CallBackFun,
NULL,&NumLine))==LINEERR_REINIT)
{Sleep(5);}
Error=lineOpen(myhTapi,0,&myhLine,0x10004,0,0,LINECALLPRIVILEGE_OWNER+
LINECALLPRIVILEGE_MONITOR,LINEMEDIAMODE_DATAMODEM,NULL);
if(Error!=0)
{
sprintf(buf,"%lx",Error);
AfxMessageBox(buf,0,MB_OK);
}
}
==========================================================================================================
//获得调制解调器句柄函数(双方)
HANDLE GetModemHandle(HLINE hLine)
{
CommID FAR *cid;
VARSTRING *vs;
LONG lrc;
DWORD dwSize;
HANDLE hModem;
char szModemName[64];
//the next four lines prepare VARSTRING structure to pass to windows through lineGetID
vs=(VARSTRING *)malloc(sizeof(VARSTRING));
if(!vs)
return NULL;
vs->dwTotalSize=sizeof(VARSTRING);
do{ //get modem handle associated with the line
if((lrc=lineGetID(myhLine,0L,NULL,LINECALLSELECT_LINE,vs,"comm/datamodem"))==0 &&
(vs->dwTotalSize<vs->dwNeededSize))
{
//the next six lines reallocate the VARSTRING structure with the amount of space
// the Windows indicates is needed to return all of the information
dwSize=vs->dwNeededSize;
free(vs);
vs=(VARSTRING *)malloc(dwSize);
if(!vs)
return NULL;
vs->dwTotalSize=dwSize;
}//end else if(error getting comm device handle)
else
break;
}while (TRUE);
cid=(CommID FAR *)((LPSTR)vs+ vs->dwStringOffset);
lstrcpy(szModemName,&cid->szModemName[0]);
hModem=cid->hModem;
return hModem;
}//end function (GetModemHandle)
==========================================================================================================
//被叫方应答函数(其中两参数均实参为回调函数lineCallBackFun的相应返回值)
void Answer(DWORD dwParam3,DWORD hDevice)
{
HCALL myhCall;
if(dwParam3==LINECALLPRIVILEGE_OWNER)//只有对呼叫具有私有特权的调用者才能应答呼叫
{
myhCall=((HCALL)hDevice);
Error=lineAnswer(myhCall,NULL,0);
if(Error)
AfxMessageBox("应答响应函数已调用成功");
}
else
AfxMessageBox("应答时线路句柄出错");
}
==========================================================================================================
//呼叫方写数据函数
void WriteThread()
{
DWORD nBytesWrite;
Error=WriteFile(myhModem,buf,N,&nBytesWrite,NULL);
Err=GetLastError();
if(Error!=0)
AfxMessageBox("数据写成功");
else
AfxMessageBox("数据写失败");
}