[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]
'공부하는 개발자 > Mobile' 카테고리의 다른 글
| Android에서 StatusBar의 시계 색깔 바꾸기 (0) | 2011/02/07 |
|---|---|
| R.java was modified manually! Reverting to generated version! (0) | 2010/05/18 |
| 모바일 프로그래밍에서 사용자 핸드폰 번호 얻기 (0) | 2009/05/19 |
| 폼 최소화 기능 삭제 (0) | 2009/05/13 |