In our program development, some industries use landline call screen, and C # as a Microsoft's important development tool, the application of a wide range of this code to implement the C # call DLL implementation call Bomb screen (in the case of a landline call display box, the box is stable and reliable, simple programming).
usingServiceDesk;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Runtime.InteropServices;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewinf{ Public Partial classForm1:form {
The key is that the following 4 lines call the DLL's declaration [DllImport ("ZSCIDUDP.dll", CallingConvention = callingconvention.stdcall, CharSet = charset.ansi, EntryPoint ="Zscidinit")] Public Static extern intZscidinit (stringAUDPS_IP,intAudps_port,BOOLAissendstate);[DllImport ("ZSCIDUDP.dll", CallingConvention = callingconvention.stdcall, CharSet = charset.ansi, EntryPoint ="Zscidfree")] Public Static extern voidZscidfree (intARef); Public intLaidiancount {Get;Set; } Public intFref {Get;Set; } Public voidZsinit () {fref= Zscidinit ("127.0.0.1",9013,false);///The first parameter is the IP to be sent to the UDP listener after the call, the second parameter is the port number of the UDP listener} Public voidZsfree () {if(Fref >0) {zscidfree (fref); Fref=0; } } PublicForm1 () {InitializeComponent (); Udplisenter (); UDP listener is implemented here}Private voidForm1_Load (Objectsender, EventArgs e) {Zsinit (); } Private voidForm1_formclosing (Objectsender, FormClosingEventArgs e) {free (); } Private voidBtn_init_click (Objectsender, EventArgs e) {init (); } Private voidBtn_free_click (Objectsender, EventArgs e) {free (); } voidinit () {Try{zsinit (); Btn_free. Enabled=true; Btn_init. Enabled=false; } Catch(Exception ex) {MessageBox.Show (ex). Message,"Zscidinit Exception"); } finally{Txt_fref.appendtext ("Initialize the fref="+ Fref +"""+Environment.NewLine); } } voidFree () {Try{Txt_fref.appendtext ("before release "Fref="+ Fref +"""+Environment.NewLine); Zsfree (); Btn_free. Enabled=false; Btn_init. Enabled=true; } Catch(Exception ex) {MessageBox.Show (ex). Message,"Zscidfree Exception"); } finally{Txt_fref.appendtext ("after release "Fref="+ Fref +"""+Environment.NewLine); } } voidStatehandler (stringdata) {txt_state. AppendText (data. ToString ()+Environment.NewLine); } Private voidUdplisenter () {Task.Factory.StartNew ()= { intUpdport =9013; UdpClient Listener=NewUdpClient (Updport); Listener. Dontfragment=true; Listener. EnableBroadcast=true; IPEndPoint Remoteipendpoint=NewIPEndPoint (Ipaddress.loopback, Updport); while(true) { Try { byte[] bytes = listener. Receive (refremoteipendpoint); stringdata =System.Text.Encoding.Default.GetString (bytes); stringPhoneNumber =getnum (data); Writelog (PhoneNumber); } Catch(Exception ex) {MessageBox.Show (ex). Message); }}}, Taskcreationoptions.longrunning|taskcreationoptions.preferfairness); } stringGetnum (stringdata) { stringPhoneNumber =""; if(!string. Isnullorwhitespace (data)) {string[] STRs = data. Split (New string[] {"\ r \ n"}, Stringsplitoptions.none); foreach(stringKinchSTRs) { string[] tttmp = K.split ('='); if(Tttmp. Length >1&& tttmp[0] =="NUM") PhoneNumber= tttmp[1]; } } returnPhoneNumber; } voidWritelog (stringNumber ) { if(!string. Isnullorwhitespace (number)) {Txt_udprecieve. AppendText ("["+ laidiancount++ +"]: "+ number +" "+ DateTime.Now.ToString ("YYYY-MM-DD HH:mm:ss") +Environment.NewLine); Laidianwriter wer=NewLaidianwriter (); Wer. Push (number); } } } }
C # Detection of Landline Call number realization method of call bounce screen