我用TAPI实现电话拨号,连续拨打20次左右,拨号模块就不行了(200)

  • 主题发起人 主题发起人 folmorse
  • 开始时间 开始时间
F

folmorse

Unregistered / Unconfirmed
GUEST, unregistred user!
我用TAPI实现电话拨号,连续拨打20次左右,然后就出现拨号模块出现故障,重启程序不能解决问题,必须重新启动机器才能恢复拨号。具体代码如下:unit CallPhone;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BaseClass, RzButton, StdCtrls, RzLstBox, RzLabel,TApi, ExtCtrls;type TCallPhoneForm = class(TBaseClassForm) RzLabel1: TRzLabel; lbxTel: TRzListBox; btnCall: TRzBitBtn; btnQuit: TRzBitBtn; btnDropCall: TRzBitBtn; lblCurStatus: TRzLabel; RzLabel2: TRzLabel; tmClose: TTimer; procedure FormCreate(Sender: TObject); procedure btnCallClick(Sender: TObject); procedure btnDropCallClick(Sender: TObject); procedure btnQuitClick(Sender: TObject); procedure tmCloseTimer(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FInitOK:Integer; FIsOK:Integer; FPhoneNos:String; FStartTime:DWORD; lineApp: THLineApp; line: THLine; call: THCall; CallParams: TlineCallParams; procedure SetPhoneNos(value:String); public { Public declarations } function LoadDevice():Integer; published property InitOK :Integer read FInitOK; property IsOK :Integer read FIsOK; property PhoneNos :String write SetPhoneNos; end;var CallPhoneForm: TCallPhoneForm;implementationuses PubVar,PubFunc,SysControl;{$R *.dfm}var buf:array[0..1023] of char; callinfo: TLineCallInfo absolute buf; IsConnected:Integer;procedure lineCallback(hDevice, dwMsg, dwCallbackInstance,dwParam1, dwParam2, dwParam3: LongInt);{$IFDEF WIN32} stdcall;{$ELSE} export;{$ENDIF}var s: string; hCall: THCall;begin if dwMsg = LINE_REPLY then { result of LineMakeCall } begin if dwParam2 < 0 then CallPhoneForm.lblCurStatus.Caption:='应答错误'; end else if dwMsg = LINE_CALLSTATE then { change in line state } begin hCall := THCall(hDevice); case dwParam1 of LINECALLSTATE_IDLE: { call terminated } if hcall <> 0 then begin lineDeallocateCall(hCall); { you must deallocate the call } CallPhoneForm.lblCurStatus.Caption:='请重新拨号......'; CallPhoneForm.btnCall.Enabled := True; CallPhoneForm.btnDropCall.Enabled := False; end; LINECALLSTATE_CONNECTED: { Service connected } if hCall <> 0 then begin s := '已经连接,'; s:=s + ' 请拿起话机准备接听'; CallPhoneForm.lblCurStatus.Caption:=s; IsConnected:=1; Sleep(CALL_WAIT_TIME); end; LINECALLSTATE_PROCEEDING: { call proceeding (dialing) } begin CallPhoneForm.lblCurStatus.Caption:='正在连接中,等待应答...'; //Sleep(CALL_WAIT_TIME); IsConnected:=1; if TAPI_MEDIA_MODE=1 then begin Sleep(CALL_WAIT_TIME); CallPhoneForm.lblCurStatus.Caption:='请拿起话机准备接听...'; end; end; LINECALLSTATE_DIALING: { dialing } CallPhoneForm.lblCurStatus.Caption:='正在拨号...'; LINECALLSTATE_DIALTONE: //{检测到拨号音} CallPhoneForm.lblCurStatus.Caption:='检测到拨号音'; LINECALLSTATE_DISCONNECTED: { disconnected } begin s := '连接断开,原因: '; if dwParam2 = LINEDISCONNECTMODE_NORMAL then s := s + '正常断开' else if dwParam2 = LINEDISCONNECTMODE_BUSY then s := s + '对方占线' else s:= s + '线路故障'; CallPhoneForm.lblCurStatus.Caption:=s; CallPhoneForm.btnDropCall.Click; end; LINECALLSTATE_BUSY: { busy } CallPhoneForm.lblCurStatus.Caption:='电话忙'; end; end;end;function TCallPhoneForm.LoadDevice():Integer;var nDevs, tapiVersion: Longint; extid: TLineExtensionID;begin { Initialize TAPI } { Zeros CallParams structure } Result:=0; FillChar(CallParams, sizeof(CallParams), 0); with CallParams do begin dwTotalSize := sizeof(CallParams); dwBearerMode := LINEBEARERMODE_VOICE; dwMediaMode := LINEMEDIAMODE_INTERACTIVEVOICE; if TAPI_MEDIA_MODE=1 then dwMediaMode := LINEMEDIAMODE_DATAMODEM; { if you don't want the dialing dialog use LINEMEDIAMODE_DATAMODEM } end; if lineInitialize(lineApp, HInstance,lineCallback, nil, nDevs) < 0 then { < 0 is an error } begin lineApp := 0; Exit; end else if nDevs = 0 then { no TAPI devices?? } begin lineShutDown(lineApp); lineApp := 0; end else if lineNegotiateAPIVersion(lineApp, 0, $00010000, $10000000,tapiVersion, extid) < 0 then { Check for version (copied from a TAPI sample) } begin lineShutDown(lineApp); lineApp := 0; end { Open a line for outbound calls (here I use first device, normally the modem) } else if lineOpen(lineApp, LINEMAPPER, line, tapiVersion, 0, 0,LINECALLPRIVILEGE_NONE, 0, @CallParams) < 0 then begin lineShutDown(lineApp); lineApp := 0; line := 0; end; if line = 0 then begin Exit; end; Result:=1;end; procedure TCallPhoneForm.FormCreate(Sender: TObject);var dial_str:String;begin inherited; FInitOK:=1; FIsOK:=0; IsConnected:=0;end;procedure TCallPhoneForm.SetPhoneNos(value:String);begin FPhoneNos:=value; lbxTel.Items.CommaText:=FPhoneNos; if lbxTel.Items.Count>0 then lbxTel.ItemIndex:=0; btnCall.Enabled:=False; btnCallClick(Self);end; procedure TCallPhoneForm.btnCallClick(Sender: TObject);var PhoneNum:string; dial_str:String; c: array[0..30] of char;begin PhoneNum:=lbxTel.SelectedItem; if Length(PhoneNum) > 0 then begin StrPCopy(c, PhoneNum); if lineMakeCall(line, call, c, 0, @CallParams) < 0 then lblCurStatus.Caption:= '拨号调用出错!' else begin btnCall.Enabled := False; btnDropCall.Enabled := True; end; end; tmClose.Enabled:=True; IsConnected:=0; FStartTime:=GetTickCount();end;procedure TCallPhoneForm.btnDropCallClick(Sender: TObject);begin inherited; if LineDrop(call, nil, 0) < 0 then lblCurStatus.Caption:= '电话挂断调用出错!'; tmClose.Enabled:=False; btnCall.Enabled:=True;end;procedure TCallPhoneForm.btnQuitClick(Sender: TObject);begin inherited; LineDrop(call, nil, 0); tmClose.Enabled:=False; Close;end;procedure TCallPhoneForm.tmCloseTimer(Sender: TObject);var cur_time:DWORD; wait_time:DWORD;begin inherited; cur_time:=GetTickCount(); wait_time:=CALL_WAIT_TIME*3; //CALL_WAIT_TIME是系统常量,默认为3000 if cur_time-FStartTime>wait_time then begin tmClose.Enabled:=False; Close; end;end;其中:CALL_WAIT_TIME是系统常量,默认为3000。请看以上代码有何问题?谢谢。请各位高手帮帮忙!小弟不胜感激!procedure TCallPhoneForm.FormDestroy(Sender: TObject);begin inherited; if line <> 0 then lineClose(line); if lineApp <> 0 then lineShutDown(lineApp);end;
 
是否有东东没有释放或某些东东需要清空,你要仔细跟踪、检查一下
 
应该不会,我在自己的公司测试没问题的,但是到了客户那里就有这种情况,另外,把那个进程杀掉,重新启动那个进程,也不能解决问题,如果有内存泄露之类的问题,是不是应该杀掉进程后,会释放的吧?
 
这个窗口的调用程序如下:procedure TMainForm.btnDialClick(Sender: TObject);begin inherited; if edtLinkTel.Text<>'' then begin CallPhoneForm:=TCallPhoneForm.Create(Self); if CallPhoneForm.LoadDevice=0 then begin CallPhoneForm.Free; ShowMsgWindow('错误:没有检测到Modem!'); Exit; end; CallPhoneForm.PhoneNos:=edtLinkTel.Text; CallPhoneForm.ShowModal; CallPhoneForm.Free; end;end;这样在主窗体里面的调用代码,有什么疑问?
 

Similar threads

后退
顶部