PC Review


Reply
Thread Tools Rate Thread

Getting Device Phone Number

 
 
Matt
Guest
Posts: n/a
 
      6th Apr 2009
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!
 
Reply With Quote
 
 
 
 
Peter Foot
Guest
Posts: n/a
 
      6th Apr 2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!


 
Reply With Quote
 
 
 
 
Matt
Guest
Posts: n/a
 
      6th Apr 2009
Thanks Peter - I'll try that!

"Peter Foot" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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!

>
>

 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      7th Apr 2009
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" wrote:

> Thanks Peter - I'll try that!
>
> "Peter Foot" wrote:
>
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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!

> >
> >

 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      7th Apr 2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" wrote:
>
>> Thanks Peter - I'll try that!
>>
>> "Peter Foot" wrote:
>>
>> > 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" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> > > 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!
>> >
>> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact Phone Number & account Phone number augustus Microsoft Outlook BCM 0 24th Jul 2009 01:15 AM
new type of phone number in phone number list when adding new contacts Boatman Microsoft Outlook Discussion 4 7th Nov 2008 01:51 AM
Can't find a phone number that is in Phone Number Field? =?Utf-8?B?TWFyaw==?= Microsoft Outlook Contacts 1 8th Nov 2006 09:04 PM
GET $50 CASH EVERY FREE CELL PHONE YOU GIVE AWAY or GET A FREE CELL PHONE or CAMERA PHONE online_store_4@yahoo.com Freeware 1 13th Feb 2006 03:40 PM
Outlook 2003 inserting +1 in phone number leads to cell phone prob timmyran Microsoft Outlook Contacts 0 27th Mar 2004 09:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:23 AM.