public static extern Int32 lineInitializeEx( // Uygulamanın, TAPI kullanımına ait handle. ref IntPtr lphLineApp, // Client uygulamaya (veya DLL) ait instance handle (null değer alabilir). IntPtr hInstance, // Geri çağrılır fonksiyonumuzun adresi. LineCallback lpfnCallback, // Uygulama adı. string lpszFriendlyAppName, // Bulunan hatların sayısı. ref UInt32 lpdwNumDevs, // TAPI tarafından desteklenen versiyonu verir. ref UInt32 lpdwAPIVersion, // LINEINITIALIZEEXPARAMS yapısı. LINEINITIALIZEEXPARAMS lpLineInitializeExParams);
private int InitializeLineDevices() { var parms = new LINEINITIALIZEEXPARAMS(); parms.dwTotalSize = parms.dwNeededSize = parms.dwUsedSize = Marshal.SizeOf(parms); parms.dwOptions = NativeMethods.LINEINITIALIZEEXOPTION_USEEVENT; parms.dwCompletionKey = 0; parms.hEvent = IntPtr.Zero; int numDevices; uint hTapi; int rc = NativeMethods.lineInitializeEx(out hTapi, IntPtr.Zero, null, _appName, out numDevices, ref _lineVersion, ref parms); if (rc == NativeMethods.LINEERR_OK) { _hTapiLine = new HTLINEAPP(hTapi, true); _evtReceivedLineEvent.SafeWaitHandle = new SafeWaitHandle(parms.hEvent, false); _lineArray = new List <TapiLine>(); for (int i = 0; i < numDevices; i++) { var line = new TapiLine(this, i); line.NewCall += HandleNewCall; line.CallStateChanged += HandleCallStateChanged; line.CallInfoChanged += HandleCallInfoChanged; line.AddressChanged += HandleAddressChanged; line.Changed += HandleLineChanged; line.Ringing += HandleLineRinging; _lineArray.Add(line); } } else { numDevices = 0; } return(numDevices); }
public PhoneRadio() { uint num; var lineinitializeexparams = new LINEINITIALIZEEXPARAMS(); int num3; LINEEXTENSIONID lineextensionid; this._hLine = IntPtr.Zero; this._hLineApp = IntPtr.Zero; this._disposed = false; uint aPIVersion = 0x20000; lineinitializeexparams = new LINEINITIALIZEEXPARAMS { dwTotalSize = Marshal.SizeOf(lineinitializeexparams), dwNeededSize = lineinitializeexparams.dwTotalSize, dwUsedSize = lineinitializeexparams.dwTotalSize, hEvent = IntPtr.Zero, dwOptions = 2 }; lineInitializeEx(out _hLineApp, IntPtr.Zero, IntPtr.Zero, "deltaProfile", out num, ref aPIVersion, ref lineinitializeexparams); lineNegotiateAPIVersion(_hLineApp, 0, 0x10004, 0x20000, out num3, out lineextensionid); lineOpen(_hLineApp, 0, out _hLine, num3, 0, 0, 4, 0x10, IntPtr.Zero); }
//********************************* // TAPIClass sınıfı constructor * //********************************* // TAPIClass sınıfı yapıcı metodu. // sAppName: Uygulama adı. public TAPIClass(string sAppName) { m_sAppName = sAppName; m_iTAPIVer = TAPISuppVer; // Uygulamaya ait handle, m_hInstance değişkenine atanıyor. m_hInstance = WindowsAPI.GetModuleHandle(null); // LineClass tipinde yeni bir koleksiyon yarat. m_ListLine = new List <LineClass>(); // Şimdi LineCallback tipinden delegenin bir örneğini yaratalım. // Temsilcimiz LineCallbackEventHandler metoduna işaret etmektedir. // Burada geri çağrılır metodumuz kaydediliyor. m_CallBack = new LineCallback(LineCallbackEventHandler); try { // LINEINITIALIZEEXPARAMS yapı nesnesi tanımlıyoruz. LINEINITIALIZEEXPARAMS initExParams = new LINEINITIALIZEEXPARAMS(); // Uygulamamız için saklı pencere olay bildirimi mekanizması seçiyoruz. initExParams.dwOptions = (int)Enums.LineInitializeExOptions.LINEINITIALIZEEXOPTION_USEHIDDENWINDOW; // Uygulamanın TAPI kaynaklarını kullanmasını başlatır ve // hazır telefon hatlarının sayısını bulur. Int32 lineErr = lineInitializeEx(ref m_hLineApp, m_hInstance, m_CallBack, m_sAppName, ref m_iNumLines, ref m_iTAPIVer, initExParams); // lineInitializeEx çağrısından dönen değeri kontrol et. if (lineErr == TAPI_SUCCESS) { // Bir hat sayısı bulunup bulunmadığını kontrol et. if (m_iNumLines > 0) { // Bulunan hatların bilgilerini doldur. InitializeTAPILines(); // Telefonumuzun kullandığı ülke ve alan kodu bulundu mu? if (!GetCurrentLocationInfo()) { //MessageBox.Show("tapiGetLocationInfo fonksiyonu çağrısı başarısız.\n" + // "Ülke ve alan kodu alınamadı."); } } else { //MessageBox.Show("Bağlı bir telefon hattı bulunamadı."); }//if m_iNumLines } else { //MessageBox.Show("lineInitializeEx fonksiyonu çağrısı başarısız."); }//if lineErr == 0 } catch (Exception ex) { //MessageBox.Show(ex.Message); } }//constructor
private static extern LineErrReturn lineInitializeEx(out IntPtr hLineApp, IntPtr hAppHandle, IntPtr lCallBack, string FriendlyAppName, out uint NumDevices, ref uint APIVersion, ref LINEINITIALIZEEXPARAMS lineExInitParams);
//original code location: //http://www.developersdex.com/vb/message.asp?p=2916&ID=%3C68D1F07B-ECB0-4A15-AFCA-2A911FC3234C%40microsoft.com%3E /// <summary> /// Gets general information about the device. /// </summary> /// <param name="manufacturer">Manufacturer.</param> /// <param name="model">Model.</param> /// <param name="revision">Revision.</param> /// <param name="serialNumber">IMEI.</param> /// <param name="subsciberId">IMSI.</param> public static void Get(out string manufacturer, out string model, out string revision, out string serialNumber, out string subsciberId) { IntPtr hLine; int dwNumDev; int num1 = 0x20000; LINEINITIALIZEEXPARAMS lineInitializeParams = new LINEINITIALIZEEXPARAMS(); lineInitializeParams.dwTotalSize = (uint)Marshal.SizeOf(lineInitializeParams); lineInitializeParams.dwNeededSize = lineInitializeParams.dwTotalSize; lineInitializeParams.dwOptions = 2; lineInitializeParams.hEvent = IntPtr.Zero; lineInitializeParams.hCompletionPort = IntPtr.Zero; #region lineInitializeEx int result = Tapi.lineInitializeEx(out hLine, IntPtr.Zero, IntPtr.Zero, null, out dwNumDev, ref num1, ref lineInitializeParams); if (result != 0) { throw new ApplicationException(string.Format("lineInitializeEx failed!\n\nError Code:{0}", result.ToString())); } #endregion #region lineNegotiateAPIVerison int version; int dwAPIVersionLow = 0x10004; int dwAPIVersionHigh = 0x20000; LINEEXTENSIONID lineExtensionID; result = Tapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow, dwAPIVersionHigh, out version, out lineExtensionID); if (result != 0) { throw new ApplicationException(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString())); } #endregion #region lineOpen IntPtr hLine2 = IntPtr.Zero; result = Tapi.lineOpen(hLine, 0, out hLine2, version, 0, IntPtr.Zero, 0x00000002, 0x00000004, IntPtr.Zero); if (result != 0) { throw new ApplicationException(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString())); } #endregion #region lineGetGeneralInfo int structSize = Marshal.SizeOf(new LINEGENERALINFO()); byte[] bytes = new byte[structSize]; byte[] tmpBytes = BitConverter.GetBytes(structSize); for (int index = 0; index < tmpBytes.Length; index++) { bytes[index] = tmpBytes[index]; } #endregion #region make initial query to retrieve necessary size result = Tapi.lineGetGeneralInfo(hLine2, bytes); // get the needed size int neededSize = BitConverter.ToInt32(bytes, 4); // resize the array bytes = new byte[neededSize]; // write out the new allocated size to the byte stream tmpBytes = BitConverter.GetBytes(neededSize); for (int index = 0; index < tmpBytes.Length; index++) { bytes[index] = tmpBytes[index]; } // fetch the information with properly size buffer result = Tapi.lineGetGeneralInfo(hLine2, bytes); if (result != 0) { #if DEBUG throw new ApplicationException(Marshal.GetLastWin32Error().ToString()); #endif //tear down Tapi.lineClose(hLine2); Tapi.lineShutdown(hLine); manufacturer = String.Empty; model = String.Empty; revision = String.Empty; serialNumber = String.Empty; subsciberId = String.Empty; return; } #endregion #region actual data fetching int size; int offset; // manufacture size = BitConverter.ToInt32(bytes, 12); offset = BitConverter.ToInt32(bytes, 16); manufacturer = Encoding.Unicode.GetString(bytes, offset, size); manufacturer = manufacturer.Substring(0, manufacturer.IndexOf('\0')); // model size = BitConverter.ToInt32(bytes, 20); offset = BitConverter.ToInt32(bytes, 24); model = Encoding.Unicode.GetString(bytes, offset, size); model = model.Substring(0, model.IndexOf('\0')); // revision size = BitConverter.ToInt32(bytes, 28); offset = BitConverter.ToInt32(bytes, 32); revision = Encoding.Unicode.GetString(bytes, offset, size); revision = revision.Substring(0, revision.IndexOf('\0')); // serial number size = BitConverter.ToInt32(bytes, 36); offset = BitConverter.ToInt32(bytes, 40); serialNumber = Encoding.Unicode.GetString(bytes, offset, size); serialNumber = serialNumber.Substring(0, serialNumber.IndexOf('\0')); // subscriber id size = BitConverter.ToInt32(bytes, 44); offset = BitConverter.ToInt32(bytes, 48); subsciberId = Encoding.Unicode.GetString(bytes, offset, size); subsciberId = subsciberId.Substring(0, subsciberId.IndexOf('\0')); #endregion //tear down Tapi.lineClose(hLine2); Tapi.lineShutdown(hLine); }
//********************************* // TAPIClass sınıfı constructor * //********************************* // TAPIClass sınıfı yapıcı metodu. // sAppName: Uygulama adı. public TAPIClass(string sAppName) { m_sAppName = sAppName; m_iTAPIVer = TAPISuppVer; // Uygulamaya ait handle, m_hInstance değişkenine atanıyor. m_hInstance = WindowsAPI.GetModuleHandle(null); // LineClass tipinde yeni bir koleksiyon yarat. m_ListLine = new List<LineClass>(); // Şimdi LineCallback tipinden delegenin bir örneğini yaratalım. // Temsilcimiz LineCallbackEventHandler metoduna işaret etmektedir. // Burada geri çağrılır metodumuz kaydediliyor. m_CallBack = new LineCallback(LineCallbackEventHandler); try { // LINEINITIALIZEEXPARAMS yapı nesnesi tanımlıyoruz. LINEINITIALIZEEXPARAMS initExParams = new LINEINITIALIZEEXPARAMS(); // Uygulamamız için saklı pencere olay bildirimi mekanizması seçiyoruz. initExParams.dwOptions = (int)Enums.LineInitializeExOptions.LINEINITIALIZEEXOPTION_USEHIDDENWINDOW; // Uygulamanın TAPI kaynaklarını kullanmasını başlatır ve // hazır telefon hatlarının sayısını bulur. Int32 lineErr = lineInitializeEx(ref m_hLineApp, m_hInstance, m_CallBack, m_sAppName, ref m_iNumLines, ref m_iTAPIVer, initExParams); // lineInitializeEx çağrısından dönen değeri kontrol et. if (lineErr == TAPI_SUCCESS) { // Bir hat sayısı bulunup bulunmadığını kontrol et. if (m_iNumLines > 0) { // Bulunan hatların bilgilerini doldur. InitializeTAPILines(); // Telefonumuzun kullandığı ülke ve alan kodu bulundu mu? if (!GetCurrentLocationInfo()) { MessageBox.Show("tapiGetLocationInfo fonksiyonu çağrısı başarısız.\n" + "Ülke ve alan kodu alınamadı."); } } else { MessageBox.Show("Bağlı bir telefon hattı bulunamadı."); }//if m_iNumLines } else { MessageBox.Show("lineInitializeEx fonksiyonu çağrısı başarısız."); }//if lineErr == 0 } catch (Exception ex) { MessageBox.Show(ex.Message); } }