I'm rewriting a C++ TAPI app I wrote a while ago in C#. Everything
works fine for the first call. Unfortunately, all subsequent calls are
completely ignored by TAPI until I restart the app again.
I remember running into this same problem with my original C++ code and
it was being caused by my failure to release all call related tapi
resources. As a point of reference the C++ app has been running quite
well for over a year.
Anyway, I beleive I'm releasing all the tapi interfaces when I'm done
with them but nothing I've done has solved the problem. I'm at a
complete loss as to what might be causing the problem. Any thoughts
would be greatly appreciated.
Here's the code:
=============== =========
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Runtime. InteropServices ;
using TAPI3Lib;
namespace CallManager
{
/// <summary>
/// Summary description for TapiMsgWindow.
/// </summary>
public class TapiMsgWindow : System.Windows. Forms.Form
{
public delegate void TapiInitializat ionDelegate(obj ect sender, bool
success);
public event TapiInitializat ionDelegate TapiInitializat ion;
public delegate void CallNotificatio nDelegate(objec t sender);
public event CallNotificatio nDelegate CallNotificatio n;
public delegate void CallStateDelega te(object sender,
TAPI3Lib.CALL_S TATE callState);
public event CallStateDelega te CallState;
public delegate void CallInfoDelegat e(object sender,
CALLINFOCHANGE_ CAUSE cic);
public event CallInfoDelegat e CallInfo;
public delegate void CallerIDEventDe legate(object sender,
CallerIDInfo cidInfo);
public event CallerIDEventDe legate CallerIDEvent;
public enum MEDIATYPE
{
MediaAudio = 8,
MediaModem = 16,
MediaFax = 32,
MediaVideo = 32768,
}
private MainForm _ParentForm = null;
private TAPI3Lib.TAPICl ass _TAPI = null;
private ITAddress ListenAddress = null;
private ITBasicCallCont rol Call = null;
private int RegEventsResult = -1;
private int mediaTypes = 0;
private bool IsNewCall = false;
private int CurrentRingCoun t = 0;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
public TapiMsgWindow()
{
InitializeCompo nent();
}
public TapiMsgWindow(M ainForm parentForm) : this()
{
_ParentForm = parentForm;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
_TAPI.Unregiste rNotifications( RegEventsResult );
_TAPI.Shutdown( );
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
this.Size = new System.Drawing. Size(300,300);
this.Text = "TapiMsgWindow" ;
}
#endregion
public bool InitTAPI()
{
bool result = false;
_TAPI = new TAPI3Lib.TAPICl ass();
try
{
_TAPI.Initializ e();
_TAPI.Event += new
ITTAPIDispatchE ventNotificatio n_EventEventHan dler(OnTapiEven t);
result = SelectAddress() ;
}
catch(Exception ex)
{
MessageBox.Show (ex.Message);
result = false;
}
if(TapiInitiali zation != null)
TapiInitializat ion(this, result);
return result;
}
private bool SelectAddress()
{
bool result = false;
ITCollection addresses = (ITCollection)_ TAPI.Addresses;
ITAddress curAddress = null;
ListenAddress = null;
//Careful here. The array is 1 based NOT 0 based;
for(int i = 1; i <= addresses.Count ; i++)
{
curAddress = (ITAddress)addr esses[i];
if(curAddress.S tate == ADDRESS_STATE.A S_INSERVICE)
{
ITMediaSupport mediaSupport = (ITMediaSupport )curAddress;
// Get the supported media types...
mediaTypes = mediaSupport.Me diaTypes;
mediaSupport = null;
if((mediaTypes & (int)MEDIATYPE. MediaAudio) ==
(int)MEDIATYPE. MediaAudio)
{
ListenAddress = curAddress;
break;
}
}
}
// Did we find the address we were looking for?
if(ListenAddres s != null)
{
RegEventsResult = _TAPI.RegisterC allNotification s(ListenAddress ,
true, true, mediaTypes, 1);
_TAPI.EventFilt er = (int)(
TAPI_EVENT.TE_C ALLNOTIFICATION |
TAPI_EVENT.TE_C ALLSTATE |
TAPI_EVENT.TE_D IGITEVENT |
TAPI_EVENT.TE_C ALLINFOCHANGE |
TAPI_EVENT.TE_A DDRESS
);
}
else
{
MessageBox.Show ("No TAPI address selected");
result = false;
}
result = true;
return result;
}
private void OnTapiEvent(TAP I_EVENT TapiEvent, object pEvent)
{
switch(TapiEven t)
{
case TAPI_EVENT.TE_C ALLSTATE:
{
OnCallStateEven t((ITCallStateE vent)pEvent);
break;
}
case TAPI_EVENT.TE_A DDRESS:
{
OnAddressEvent( (ITAddressEvent )pEvent);
break;
}
case TAPI_EVENT.TE_C ALLNOTIFICATION :
{
OnCallNotifyEve nt((ITCallNotif icationEvent)pE vent);
break;
}
case TAPI_EVENT.TE_C ALLINFOCHANGE:
{
OnCallInfoEvent ((ITCallInfoCha ngeEvent)pEvent );
break;
}
case TAPI_EVENT.TE_P HONEEVENT:
{
Marshal.Release ComObject(pEven t);
break;
}
case TAPI_EVENT.TE_D IGITEVENT:
{
OnDigitEvent((I TDigitDetection Event)pEvent);
break;
}
case TAPI_EVENT.TE_G ATHERDIGITS:
{
OnGatherDigits( (ITDigitsGather edEvent)pEvent) ;
break;
}
case TAPI_EVENT.TE_C ALLMEDIA:
{
OnCallMediaChan ged((ITCallMedi aEvent)pEvent);
break;
}
case TAPI_EVENT.TE_T ONEEVENT:
{
OnCallToneEvent ((ITToneDetecti onEvent)pEvent) ;
break;
}
default:
{
Marshal.Release ComObject(pEven t);
break;
}
}
}
private void OnCallInfoEvent (ITCallInfoChan geEvent pEvent)
{
Console.WriteLi ne("CallInfoEve nt:");
Console.WriteLi ne(pEvent.Cause .ToString());
if(CallInfo != null)
CallInfo(this, pEvent.Cause);
try
{
if(pEvent.Cause == CALLINFOCHANGE_ CAUSE.CIC_CALLE RID)
{
if(CurrentRingC ount >= 2)
{
string callerIDName =
pEvent.Call.get _CallInfoString (CALLINFO_STRIN G.CIS_CALLERIDN AME);
string callerIDNumber =
pEvent.Call.get _CallInfoString (CALLINFO_STRIN G.CIS_CALLERIDN UMBER);
CallerIDInfo cidInfo = new CallerIDInfo(ca llerIDNumber,
callerIDName);
if(CallerIDEven t != null)
CallerIDEvent(t his, cidInfo);
}
}
}
catch(Exception ex)
{
MessageBox.Show (string.Format( "CallInfoEv ent failed with the
following exception:{0}", ex.Message));
}
finally
{
Marshal.Release ComObject(pEven t);
}
}
private void OnDigitEvent(IT DigitDetectionE vent pEvent)
{
try
{
byte digit = pEvent.Digit;
int digitMode = pEvent.DigitMod e;
}
finally
{
Marshal.Release ComObject(pEven t);
}
}
private void OnGatherDigits( ITDigitsGathere dEvent pEvent)
{
try
{
}
finally
{
Marshal.Release ComObject(pEven t);
}
}
private void OnCallMediaChan ged(ITCallMedia Event pEvent)
{
try
{
}
finally
{
Marshal.Release ComObject(pEven t);
}
}
private void OnCallToneEvent (ITToneDetectio nEvent pEvent)
{
try
{
}
finally
{
Marshal.Release ComObject(pEven t);
}
}
private void OnAddressEvent( ITAddressEvent pEvent)
{
ADDRESS_EVENT addressEvent = pEvent.Event;
Marshal.Release ComObject(pEven t);
switch(addressE vent)
{
case ADDRESS_EVENT.A E_RINGING:
{
CurrentRingCoun t++;
break;
}
}
}
private void OnCallNotifyEve nt(ITCallNotifi cationEvent pEvent)
{
CALL_NOTIFICATI ON_EVENT callEvent = pEvent.Event;
if(Call != null)
{
Marshal.Release ComObject(Call) ;
Call = null;
}
Call = (ITBasicCallCon trol)(object)pE vent.Call;
IsNewCall = true;
Marshal.Release ComObject(pEven t);
switch(callEven t)
{
case CALL_NOTIFICATI ON_EVENT.CNE_MO NITOR:
{
break;
}
case CALL_NOTIFICATI ON_EVENT.CNE_OW NER:
{
break;
}
}
if(CallNotifica tion != null)
CallNotificatio n(this);
}
private void OnCallStateEven t(ITCallStateEv ent pEvent)
{
CALL_STATE state = pEvent.State;
Marshal.Release ComObject(pEven t);
if(CallState != null)
CallState(this, state);
switch(state)
{
case CALL_STATE.CS_I DLE:
{
break;
}
case CALL_STATE.CS_I NPROGRESS:
{
break;
}
case CALL_STATE.CS_O FFERING:
{
break;
}
case CALL_STATE.CS_C ONNECTED:
{
break;
}
case CALL_STATE.CS_Q UEUED:
{
break;
}
case CALL_STATE.CS_H OLD:
{
break;
}
case CALL_STATE.CS_D ISCONNECTED:
{
CurrentRingCoun t = 0;
DisconnectTheCa ll();
ReleaseTheCall( );
IsNewCall = false;
break;
}
}
}
private void DisconnectTheCa ll()
{
Call.Disconnect (DISCONNECT_COD E.DC_NORMAL);
}
private void ReleaseTheCall( )
{
Marshal.Release ComObject(Call) ;
Call = null;
}
}
} 7 18726
Well, I got it working by releasing TAPIClass and ITAddress objects and
re-initializing these objects after each call. It's working ok but
this seems a little strange that I would need to go to this extreme.
Thoughts, comments, and suggestions appreciated.
SteveV
Thanks for the links. I had completely missed the MS kb article. I
had seen Helen's TAPI sample but it's TAPI2 and I was hoping to use my
existing TAPI3 c++ app as a model to minimize the amount of code
rewrite required to convert it to C#. Bummer.
Thanks again,
Steve
Steven
I'm using Tapi with C#. The difference is that i wrote a dll and call it by
C# (everythings, C# just call the functions).
Best regards,
Vuong
Tran xuan
"St**********@h otmail.com" wrote: Thanks for the links. I had completely missed the MS kb article. I had seen Helen's TAPI sample but it's TAPI2 and I was hoping to use my existing TAPI3 c++ app as a model to minimize the amount of code rewrite required to convert it to C#. Bummer.
Thanks again, Steve
Hi Steven,
I am starting my first steps in tapi using c #, i find it difficult but I
think your code gives me a good starting point.
Trying to run your code gave errors like :
* The type or namespace name 'MainForm' could not be found (are you missing
a using directive or an assembly reference?)
I tried to solve it by making new windows form of midi type with name
MainForm in namspace CallManger.
* The type or namespace name 'CallerIDInfo' could not be found (are you
missing a using directive or an assembly reference?)
Which i coul not find or solve.
So i will appreciate if you gave a hint how to make it work . or send me a
demo code.
It will be amazing to see working c# code for tapi Applications.
Thanks
Dr.Sameh Ali dr***********@h otmail.com
"St**********@h otmail.com" wrote: I'm rewriting a C++ TAPI app I wrote a while ago in C#. Everything works fine for the first call. Unfortunately, all subsequent calls are completely ignored by TAPI until I restart the app again.
I remember running into this same problem with my original C++ code and it was being caused by my failure to release all call related tapi resources. As a point of reference the C++ app has been running quite well for over a year.
Anyway, I beleive I'm releasing all the tapi interfaces when I'm done with them but nothing I've done has solved the problem. I'm at a complete loss as to what might be causing the problem. Any thoughts would be greatly appreciated.
Here's the code: =============== =========
using System; using System.Drawing; using System.Collecti ons; using System.Componen tModel; using System.Windows. Forms; using System.Runtime. InteropServices ;
using TAPI3Lib;
namespace CallManager { /// <summary> /// Summary description for TapiMsgWindow. /// </summary> public class TapiMsgWindow : System.Windows. Forms.Form { public delegate void TapiInitializat ionDelegate(obj ect sender, bool success); public event TapiInitializat ionDelegate TapiInitializat ion;
public delegate void CallNotificatio nDelegate(objec t sender); public event CallNotificatio nDelegate CallNotificatio n;
public delegate void CallStateDelega te(object sender, TAPI3Lib.CALL_S TATE callState); public event CallStateDelega te CallState;
public delegate void CallInfoDelegat e(object sender, CALLINFOCHANGE_ CAUSE cic); public event CallInfoDelegat e CallInfo;
public delegate void CallerIDEventDe legate(object sender, CallerIDInfo cidInfo); public event CallerIDEventDe legate CallerIDEvent;
public enum MEDIATYPE { MediaAudio = 8, MediaModem = 16, MediaFax = 32, MediaVideo = 32768, }
private MainForm _ParentForm = null; private TAPI3Lib.TAPICl ass _TAPI = null; private ITAddress ListenAddress = null; private ITBasicCallCont rol Call = null; private int RegEventsResult = -1; private int mediaTypes = 0;
private bool IsNewCall = false; private int CurrentRingCoun t = 0;
/// <summary> /// Required designer variable. /// </summary> private System.Componen tModel.Containe r components = null;
public TapiMsgWindow() { InitializeCompo nent(); }
public TapiMsgWindow(M ainForm parentForm) : this() { _ParentForm = parentForm; }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Disp ose(); _TAPI.Unregiste rNotifications( RegEventsResult ); _TAPI.Shutdown( ); } } base.Dispose( disposing ); }
#region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeCompo nent() { this.components = new System.Componen tModel.Containe r(); this.Size = new System.Drawing. Size(300,300); this.Text = "TapiMsgWindow" ; } #endregion
public bool InitTAPI() { bool result = false; _TAPI = new TAPI3Lib.TAPICl ass();
try { _TAPI.Initializ e(); _TAPI.Event += new ITTAPIDispatchE ventNotificatio n_EventEventHan dler(OnTapiEven t); result = SelectAddress() ; }
catch(Exception ex) { MessageBox.Show (ex.Message); result = false; }
if(TapiInitiali zation != null) TapiInitializat ion(this, result);
return result; }
private bool SelectAddress() { bool result = false; ITCollection addresses = (ITCollection)_ TAPI.Addresses; ITAddress curAddress = null; ListenAddress = null;
//Careful here. The array is 1 based NOT 0 based; for(int i = 1; i <= addresses.Count ; i++) { curAddress = (ITAddress)addr esses[i];
if(curAddress.S tate == ADDRESS_STATE.A S_INSERVICE) { ITMediaSupport mediaSupport = (ITMediaSupport )curAddress;
// Get the supported media types... mediaTypes = mediaSupport.Me diaTypes; mediaSupport = null;
if((mediaTypes & (int)MEDIATYPE. MediaAudio) == (int)MEDIATYPE. MediaAudio) { ListenAddress = curAddress; break; } } }
// Did we find the address we were looking for? if(ListenAddres s != null) { RegEventsResult = _TAPI.RegisterC allNotification s(ListenAddress , true, true, mediaTypes, 1);
_TAPI.EventFilt er = (int)( TAPI_EVENT.TE_C ALLNOTIFICATION | TAPI_EVENT.TE_C ALLSTATE | TAPI_EVENT.TE_D IGITEVENT | TAPI_EVENT.TE_C ALLINFOCHANGE | TAPI_EVENT.TE_A DDRESS ); }
else { MessageBox.Show ("No TAPI address selected"); result = false; }
result = true; return result; }
private void OnTapiEvent(TAP I_EVENT TapiEvent, object pEvent) { switch(TapiEven t) { case TAPI_EVENT.TE_C ALLSTATE: { OnCallStateEven t((ITCallStateE vent)pEvent); break; }
case TAPI_EVENT.TE_A DDRESS: { OnAddressEvent( (ITAddressEvent )pEvent); break; }
case TAPI_EVENT.TE_C ALLNOTIFICATION : { OnCallNotifyEve nt((ITCallNotif icationEvent)pE vent); break; }
case TAPI_EVENT.TE_C ALLINFOCHANGE: { OnCallInfoEvent ((ITCallInfoCha ngeEvent)pEvent ); break; }
case TAPI_EVENT.TE_P HONEEVENT: { Marshal.Release ComObject(pEven t); break; }
case TAPI_EVENT.TE_D IGITEVENT: { OnDigitEvent((I TDigitDetection Event)pEvent); break; }
case TAPI_EVENT.TE_G ATHERDIGITS: { OnGatherDigits( (ITDigitsGather edEvent)pEvent) ; break; }
case TAPI_EVENT.TE_C ALLMEDIA: { OnCallMediaChan ged((ITCallMedi aEvent)pEvent); break; }
case TAPI_EVENT.TE_T ONEEVENT: { OnCallToneEvent ((ITToneDetecti onEvent)pEvent) ; break; }
default: { Marshal.Release ComObject(pEven t); break; } } }
private void OnCallInfoEvent (ITCallInfoChan geEvent pEvent) { Console.WriteLi ne("CallInfoEve nt:"); Console.WriteLi ne(pEvent.Cause .ToString());
if(CallInfo != null) CallInfo(this, pEvent.Cause);
try { if(pEvent.Cause == CALLINFOCHANGE_ CAUSE.CIC_CALLE RID) { if(CurrentRingC ount >= 2) { string callerIDName = pEvent.Call.get _CallInfoString (CALLINFO_STRIN G.CIS_CALLERIDN AME); string callerIDNumber = pEvent.Call.get _CallInfoString (CALLINFO_STRIN G.CIS_CALLERIDN UMBER);
CallerIDInfo cidInfo = new CallerIDInfo(ca llerIDNumber, callerIDName);
if(CallerIDEven t != null) CallerIDEvent(t his, cidInfo); }
} }
catch(Exception ex) { MessageBox.Show (string.Format( "CallInfoEv ent failed with the following exception:{0}", ex.Message)); }
finally { Marshal.Release ComObject(pEven t); }
hala dr. sameh
i quick-checked that code...mainform is just the parent form...and that
calledidinfo is just used for even triggereing as i understood...u can remove
them all and/or rewrite some parts of the code...
or just use/learn from my code in the other thread...
salam... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: j_mckitrick |
last post by:
I've been looking all over for this solution, but I cannot find it. I
cannot get even the simple demos for BLT to work. At the first use of
any Pmw.Blt.* call, I get this error:
_tkinter.TclError: invalid command name "::blt::vector"
Is there some trick with the library location I need to be aware of?
jonathon
|
by: Brian |
last post by:
When using this:
import parallel
p = parallel.Parallel() #open LPT1
p.setData(0x55)
I get this:
|
by: BizTalk Architect |
last post by:
Hello,
C# + TAPI
Anyone know a routine which will query the local TAPI provider for all
available telephone numbers for a call to be transfered to?
Thanks....
|
by: Dr.Sameh Ali |
last post by:
I am trying to build IVR system using c# . i know that .net wrapper for tapi
does not work well. but it seems that many made it work.
So my question:
Is there any hope to find a working code that may show how to start in tapi
and utilizing Text to speach engines to respond to call?
Any hints will be appreciated.
Dr.Sameh Ali
|
by: Tommy Vercetti |
last post by:
With Visual Studio .NET 2003, I create a new project -> C++ -> Class
library (.NET).
The instant I include a C++ header file such as:
#include <string>
or any other standard C++ header I can think of, the project won't build:
Linking...
| |
by: peteh |
last post by:
Hi All;
I am trying to test the web services consumer example on a DB2 v9 ESE
Windows server. I have tried 2 methods which both return the same
error:
-----------------------------------------------------------------------
SQL0443N Routine "DB2XML.SOAPHTTPV"
(specific name "SOAPHTTPVIVO") has returned an error SQLSTATE with
diagnostic...
|
by: PW |
last post by:
Hi,
I just bought a SanDisk Cruzer 4GB "U3" thumb drive. Is it possible
to run an Access 2003 MDE off of one, complete with data? If so, what
would I have to do to get it to work?
Just curious. No Biggie! I thought I'd take a break from writing
code and try something different. I guess I could go fishing :-)
-paulw
|
by: Soren S. Jorgensen |
last post by:
Hi,
I'm trying to read some messages (native structs) from a kernel mode
mini-filter driver. I'm using my own implementation of IAsyncResult to
pack/unpack the NativeOverlapped structure, and waiting for the result to
arrive.
To read the messages frm the kernek driver i'm using native function:
HRESULT WINAPI FilterGetMessage(
IN HANDLE...
|
by: RSL101 |
last post by:
Dear DBAs.
I am wondering if anyone gotten good results leaving the,
Monitor health of instance and databases (HEALTH_MON) = ON
I find the default ON setting causes more problem than its worth, its
trying to run auto stats update and stuffs and got in the way of
normal operation. Is that your experience, if not what I am doing
wrong...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |