Getting Device Phone Number

M

Matt

Hi

I'm trying to get the Phone Number that the device uses to make outgoing
calls.

I've found two methods but neither seem conclusive and can return blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
P

Peter Foot

The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility
 
M

Matt

Thanks Peter - I'll try that!

Peter Foot said:
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Matt said:
Hi

I'm trying to get the Phone Number that the device uses to make outgoing
calls.

I've found two methods but neither seem conclusive and can return blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
M

Matt

Hi Peter,

I tried that but "SmsGetPhoneNumber" returns a large negative number
(-2147467259) so the routine fails :(

Could you point me in the direction of the TAPI solution?

Thanks

Matt

Matt said:
Thanks Peter - I'll try that!

Peter Foot said:
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Matt said:
Hi

I'm trying to get the Phone Number that the device uses to make outgoing
calls.

I've found two methods but neither seem conclusive and can return blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 
C

Chris Tacke, eMVP

See this:

http://msdn.microsoft.com/en-us/library/ms880645.aspx


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

Matt said:
Hi Peter,

I tried that but "SmsGetPhoneNumber" returns a large negative number
(-2147467259) so the routine fails :(

Could you point me in the direction of the TAPI solution?

Thanks

Matt

Matt said:
Thanks Peter - I'll try that!

Peter Foot said:
The Own Numbers feature of the SIM card is up to the operator and usage
varies greatly. The SystemState.OwnerPhoneNumber relies on the user
having
entered their user information when they setup the device.
To retrieve the actual device number you can either use TAPI, or in
most
cases the SmsGetPhoneNumber method.

[DllImport("sms.dll")]
private static extern int SmsGetPhoneNumber(byte[] buffer);


usage:-


string phoneNumber = string.Empty;

byte[] buffer = new byte[516];
int hresult = SmsGetPhoneNumber(buffer);

if(hresult == 0)
{
phoneNumber = System.Text.Encoding.Unicode.GetString(buffer, 4,
buffer.Length - 4);
int nullIndex = phoneNumber.IndexOf("\0");
if(nullIndex > -1)
{
phoneNumber = phoneNumber.Substring(0, nullIndex);
}


Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Hi

I'm trying to get the Phone Number that the device uses to make
outgoing
calls.

I've found two methods but neither seem conclusive and can return
blank on
some devices:

OpenNETCF.Phone.Sim.Sim sim = new OpenNETCF.Phone.Sim.Sim();
if (sim.OwnNumbers.Count > 0)
{
string sMyNumber = sim.OwnNumbers[0].Address;
labelPhoneNo.Text = sMyNumber;
}
else
{
labelPhoneNo.Text =
SystemState.OwnerPhoneNumber.ToString();

Is there a better solution?

Many Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top