Thread: TAPI
View Single Post
Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

Re: TAPI

 
0
  #6
Aug 20th, 2008
How would you compile this in Dev?

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using JulMar.Tapi3;
  5.  
  6. namespace TestTapi
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. TTapi tapi = new TTapi();
  13. TCall call = null; TAddress modemAddr = null;
  14.  
  15. tapi.Initialize();
  16. tapi.TE_CALLNOTIFICATION += delegate(object sender, TapiCallNotificationEventArgs e)
  17. {
  18. Console.WriteLine("New call {0} detected from {1}", e.Call.ToString(), e.Event);
  19. };
  20. tapi.TE_CALLSTATE += delegate(object sender, TapiCallStateEventArgs e)
  21. {
  22. Console.WriteLine("{0}:{4} has changed state to {1} due to {2} - current={3}:{5}",
  23. e.Call, e.State, e.Cause, e.Call == call, e.Call.GetHashCode(), (call != null) ? call.GetHashCode() : 0);
  24. if (e.State == CALL_STATE.CS_INPROGRESS && e.Call == call)
  25. {
  26. Console.WriteLine("Dropping call");
  27. e.Call.Disconnect(DISCONNECT_CODE.DC_NORMAL);
  28. }
  29. };
  30.  
  31. foreach (TAddress addr in tapi.Addresses)
  32. {
  33. if (String.Compare(addr.ServiceProviderName, "unimdm.tsp", true) == 0 &&
  34. addr.QueryMediaType(TAPIMEDIATYPES.AUDIO))
  35. modemAddr = addr;
  36. }
  37.  
  38. if (modemAddr != null)
  39. {
  40. Console.WriteLine("{0} = {1} ({3}) [{2}]", modemAddr.AddressName, modemAddr.State, modemAddr.ServiceProviderName, modemAddr.DialableAddress);
  41. modemAddr.Monitor(TAPIMEDIATYPES.AUDIO);
  42. ConsoleKey ki = ConsoleKey.A;
  43.  
  44. while (ki != ConsoleKey.Q)
  45. {
  46. // Flip the auto-destroy flag
  47. if (ki == ConsoleKey.D)
  48. {
  49. tapi.AutoDestroyCalls = !tapi.AutoDestroyCalls;
  50. Console.WriteLine("Set AutoDestroy to {0}", tapi.AutoDestroyCalls);
  51. }
  52. // List existing calls
  53. else if (ki == ConsoleKey.L)
  54. {
  55. foreach (TCall _call in modemAddr.EnumerateCalls())
  56. {
  57. Console.WriteLine("Existing call found: {0}:{1}", _call, _call.GetHashCode());
  58. _call.Dispose(); // Go ahead and dump it
  59. }
  60. }
  61. // Create a new call
  62. else
  63. {
  64. call = modemAddr.CreateCall("5551213", LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.DATAMODEM);
  65. Console.WriteLine("Created new call {0}:{1}", call, call.GetHashCode());
  66. try
  67. {
  68. // This will fail if existing call interface is still around (i.e. not disposed)
  69. call.Connect(false);
  70. }
  71. catch (TapiException ex)
  72. {
  73. Console.WriteLine(ex.Message);
  74. }
  75. }
  76. Console.WriteLine("Press a key to try another call.. Q to quit");
  77. ki = Console.ReadKey().Key;
  78. }
  79. }
  80.  
  81. // This will destroy any outstanding interfaces
  82. tapi.Shutdown();
  83.  
  84. // Call should be disposed here.. state will be CS_UNKNOWN
  85. if (call != null)
  86. Console.WriteLine("{0} {1}", call, call.CallState);
  87. }
  88. }
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote