public struct PhoneAddress { /// The address type. public AddressType AddressType; /// The phone number in string format. public String Address; }
unsafe public static PhoneAddress SIMPhoneNumber() { PhoneAddress phoneAddress = 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; phoneAddress.AddressType = (AddressType)Marshal.ReadInt32((IntPtr)pCurrent); pCurrent += Marshal.SizeOf(phoneAddress.AddressType); phoneAddress.Address = Marshal.PtrToStringUni((IntPtr)pCurrent); } return phoneAddress; }
Trackback URI
http://deng-i.net/blog/dream/trackback/433