2009/05/19 15:48

[code c#]
 using System.Runtime.InteropServices; // for DllImport

[DllImport("sms.dll")]
private static extern IntPtr SmsGetPhoneNumber(IntPtr psmsaAddress);

 public enum AddressType
{
       /// Unknown phone number type.
       Unknown,
       /// International phone number.
       International,
       /// National phone number.
       National,
       /// Network-specific phone number.
       NetworkSpecific,
       /// Subscriber phone number.
       Subscriber,
       /// Alphanumeric phone number.
       Alphanumeric,
       /// Abbreviated phone number.
       Abbreviated
}

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;
}
[/code]

Posted by 보댕