/// <summary> /// Gets the phone number from the SIM. /// </summary> /// <returns>PhoneAddress structure with phone number.</returns> public static unsafe PhoneAddress GetPhoneNumber() { PhoneAddress phoneaddr = new PhoneAddress(); Byte[] buffer = new Byte[516]; fixed (byte* pAddr = buffer) { IntPtr res = SmsGetPhoneNumber((IntPtr)pAddr); if (res != IntPtr.Zero) throw new Exception("Could not get phone number from SIM"); byte* pCurrent = pAddr; phoneaddr.AddressType = (AddressType)Marshal.ReadInt32((IntPtr)pCurrent); pCurrent += Marshal.SizeOf(phoneaddr.AddressType); phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent); } return phoneaddr; }
public string CogerNtelefono() { string numero = ""; PhoneAddress phoneaddr = new PhoneAddress(); try { phoneaddr = Sim.GetPhoneNumber(); numero = phoneaddr.Address; } catch { numero = "000000000"; // MessageBox.Show("Telephone number not available."); } return numero; }