Mobile Connections Sample Code
For those of you who were asking, here's the sample code i've used in the Managed Code example of my presentation today in Mobile Connections. Create a new VB Project to begin.
Add these Import statements to the top of the code page:
Imports Microsoft.WindowsMobile.Telephony.Phone Imports Microsoft.WindowsMobile.PocketOutlook
Here's the code to send an SMS:
Dim smsM As New SmsMessage("14250010001", "Hello MEDC 2006") smsM.Send()
so much simpler compared to the C++ code needed to send an SMS in Embedded VC.
void SendSMS(BOOL bSendConfirmation, BOOL bUseDefaultSMSC, LPCTSTR lpszSMSC, LPCTSTR lpszRecipient, LPCTSTR lpszMessage) { SMS_HANDLE smshHandle; SMS_ADDRESS smsaSource; SMS_ADDRESS smsaDestination; TEXT_PROVIDER_SPECIFIC_DATA tpsd; SMS_MESSAGE_ID smsmidMessageID; // try to open an SMS Handle if(FAILED(SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL))) { MessageBox(NULL, (LPCTSTR)LoadString(ghInstance, IDS_ERROR_SMSOPEN, 0, 0), (LPCTSTR)LoadString(ghInstance, IDS_CAPTION_ERROR, 0, 0), MB_OK | MB_ICONERROR); return; } // Create the source address if(!bUseDefaultSMSC) { smsaSource.smsatAddressType = SMSAT_INTERNATIONAL; _tcsncpy(smsaSource.ptsAddress, lpszSMSC, SMS_MAX_ADDRESS_LENGTH); } // Create the destination address smsaDestination.smsatAddressType = SMSAT_INTERNATIONAL; _tcsncpy(smsaDestination.ptsAddress, lpszRecipient, SMS_MAX_ADDRESS_LENGTH); // Set up provider specific data memset(&tpsd, 0, sizeof(tpsd)); tpsd.dwMessageOptions = bSendConfirmation ? PS_MESSAGE_OPTION_STATUSREPORT : PS_MESSAGE_OPTION_NONE; tpsd.psMessageClass = PS_MESSAGE_CLASS1; tpsd.psReplaceOption = PSRO_NONE; tpsd.dwHeaderDataSize = 0; // Send the message, indicating success or failure if(SUCCEEDED(SmsSendMessage(smshHandle, ((bUseDefaultSMSC) ? NULL : &smsaSource), &smsaDestination, NULL, (PBYTE) lpszMessage, _tcslen(lpszMessage) * sizeof(TCHAR), (PBYTE) &tpsd, sizeof(TEXT_PROVIDER_SPECIFIC_DATA), SMSDE_OPTIMAL, SMS_OPTION_DELIVERY_NONE, &smsmidMessageID))) { MessageBox(NULL, LPCTSTR)LoadString(ghInstance, IDS_SMSSENT, 0, 0), (LPCTSTR)LoadString(ghInstance, IDS_CAPTION_SUCCESS, 0, 0), MB_OK); } else { MessageBox(NULL, (LPCTSTR)LoadString(ghInstance, IDS_ERROR_SMSSEND, 0, 0), (LPCTSTR)LoadString(ghInstance, IDS_CAPTION_ERROR, 0, 0), MB_OK | MB_ICONERROR); } // clean up VERIFY(SUCCEEDED(SmsClose(smshHandle))); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd) { SendSMS(gbSendConfirmation, gbUseDefault, gpszServer, gpszRecipient, gpszMessage); return 0; }
*duh*
Here's the code to make a phone call:
Dim myPhone As New Microsoft.WindowsMobile.Telephony.Phone myPhone.Talk("14250010001")
Code to add a new contact using POOM:
Dim myContact As New Contact myContact.ShowDialog()
and finally, code to call the Picture Picker Dialog:
Dim myPictures As New Microsoft.WindowsMobile.Forms.SelectPictureDialog myPictures.ShowDialog() Dim myImage As New System.Drawing.Bitmap(myPictures.FileName) PictureBox1.Image = myImage
Let me know if you like to see more sample code.
Comments
- Anonymous
January 20, 2007
Hmmm, any C++ programmer could've designed an easier to use interface than the C++ one provided by MSFT.