locked
Failed to call fucntion :SmsDevice::GetDefault()

    Question

  • Hi,everyone:
    I wrote a function to send a message,but it did not work.
    After calling SmsDevice::GetDefault(),it throws a expection as "The service has not been started!".
    How can i do?
    thanks.

    bool MainPage::SendMessage(String^ phoneNumber,String^ MessageBody)
    {
    	try
    	{
    
    		SmsDevice^ device = SmsDevice::GetDefault();
    
    		if (device == nullptr)
    		{
    			return false;
    		}
    
    		SmsTextMessage^ Message = gcnew SmsTextMessage;
    		Message->To = PhoneNumber;
    		Message->Body = MessageBody;
    
    		SendSmsMessageOperation^ op = device->SendMessageAsync(Message);
    		
    		if (op == nullptr)
    		{
    			return false;
    		}
    
    		op->Start();
    
    	}
    	catch(Exception^ ex)
    	{
    
    		String^ reason = ex->ToString();
    
    		MessageDialog^ tip = ref new MessageDialog( reason );
    		tip->ShowAsync()->Start();
    		return false;
    	}
    	return true;
    }
    
    

     

     


    • Edited by TOM.tong Friday, December 30, 2011 1:59 AM
    Friday, December 30, 2011 1:58 AM

Answers