Fail to access SIM info using Phone APIs

G

Guest

Dear All,

I've read the article about Phone API at
http://msdn.microsoft.com/smartclie...ibrary/en-us/dnnetcomp/html/netcfphoneapi.asp
.. Then I've tried to run the sample program and only added one more line to
get the device phone number in the Form1_Load method:
private void Form1_Load(object sender, System.EventArgs e)
{
string phoneNum = Microsoft.Wireless.Sim.GetPhoneNumber().Address;
Microsoft.Wireless.Phone.MakeCall("5555551234");
}

However, the API cannot read the phone number and throws the exception.

unsafe public static 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"); //
throws this exception
byte *pCurrent = pAddr;
phoneaddr.AddressType =
(AddressType)Marshal.ReadInt32((IntPtr)pCurrent);
pCurrent += Marshal.SizeOf(phoneaddr.AddressType);
phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);
}
return phoneaddr;
}

I'm using O2 MINI. I can make phone calls without problems. May anyone let
me know what's wrong I got and how to solve it. Thanks in advance.

Albert
 
P

Peter Foot [MVP]

I've seen this and I believe that SmsGetPhoneNumber depends on operator
settings. What is the error result returned in the res member?

Peter
 
G

Guest

Thanks, Peter. The return value of res is -2147467259.

Albert

Peter Foot said:
I've seen this and I believe that SmsGetPhoneNumber depends on operator
settings. What is the error result returned in the res member?

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Albert said:
Dear All,

I've read the article about Phone API at
http://msdn.microsoft.com/smartclie...ibrary/en-us/dnnetcomp/html/netcfphoneapi.asp
. Then I've tried to run the sample program and only added one more line
to
get the device phone number in the Form1_Load method:
private void Form1_Load(object sender, System.EventArgs e)
{
string phoneNum = Microsoft.Wireless.Sim.GetPhoneNumber().Address;
Microsoft.Wireless.Phone.MakeCall("5555551234");
}

However, the API cannot read the phone number and throws the exception.

unsafe public static 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"); //
throws this exception
byte *pCurrent = pAddr;
phoneaddr.AddressType =
(AddressType)Marshal.ReadInt32((IntPtr)pCurrent);
pCurrent += Marshal.SizeOf(phoneaddr.AddressType);
phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);
}
return phoneaddr;
}

I'm using O2 MINI. I can make phone calls without problems. May anyone let
me know what's wrong I got and how to solve it. Thanks in advance.

Albert
 
P

Peter Foot [MVP]

Which for info is "Unspecified error" according to the error lookup tool
from eVC.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Albert said:
Thanks, Peter. The return value of res is -2147467259.

Albert

Peter Foot said:
I've seen this and I believe that SmsGetPhoneNumber depends on operator
settings. What is the error result returned in the res member?

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Albert said:
Dear All,

I've read the article about Phone API at
http://msdn.microsoft.com/smartclie...ibrary/en-us/dnnetcomp/html/netcfphoneapi.asp
. Then I've tried to run the sample program and only added one more
line
to
get the device phone number in the Form1_Load method:
private void Form1_Load(object sender, System.EventArgs e)
{
string phoneNum = Microsoft.Wireless.Sim.GetPhoneNumber().Address;
Microsoft.Wireless.Phone.MakeCall("5555551234");
}

However, the API cannot read the phone number and throws the exception.

unsafe public static 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"); //
throws this exception
byte *pCurrent = pAddr;
phoneaddr.AddressType =
(AddressType)Marshal.ReadInt32((IntPtr)pCurrent);
pCurrent += Marshal.SizeOf(phoneaddr.AddressType);
phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);
}
return phoneaddr;
}

I'm using O2 MINI. I can make phone calls without problems. May anyone
let
me know what's wrong I got and how to solve it. Thanks in advance.

Albert
 
G

Guest

Peter, many thanks for your info again.

Albert

Peter Foot said:
Which for info is "Unspecified error" according to the error lookup tool
from eVC.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Albert said:
Thanks, Peter. The return value of res is -2147467259.

Albert

Peter Foot said:
I've seen this and I believe that SmsGetPhoneNumber depends on operator
settings. What is the error result returned in the res member?

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Dear All,

I've read the article about Phone API at
http://msdn.microsoft.com/smartclie...ibrary/en-us/dnnetcomp/html/netcfphoneapi.asp
. Then I've tried to run the sample program and only added one more
line
to
get the device phone number in the Form1_Load method:
private void Form1_Load(object sender, System.EventArgs e)
{
string phoneNum = Microsoft.Wireless.Sim.GetPhoneNumber().Address;
Microsoft.Wireless.Phone.MakeCall("5555551234");
}

However, the API cannot read the phone number and throws the exception.

unsafe public static 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"); //
throws this exception
byte *pCurrent = pAddr;
phoneaddr.AddressType =
(AddressType)Marshal.ReadInt32((IntPtr)pCurrent);
pCurrent += Marshal.SizeOf(phoneaddr.AddressType);
phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent);
}
return phoneaddr;
}

I'm using O2 MINI. I can make phone calls without problems. May anyone
let
me know what's wrong I got and how to solve it. Thanks in advance.

Albert
 
Top