SmsOpen (Compact 2013)
3/26/2014
This function opens the Short Message Service (SMS) Messaging component.
Syntax
HRESULT SmsOpen (
const LPCTSTR ptsMessageProtocol,
const DWORD dwMessageModes,
SMS_HANDLE* const psmshHandle,
HANDLE* const phMessageAvailableEvent
);
Parameters
- [in] ptsMessageProtocol
Pointer to a SMS Message Type Constants string value indicating the SMS protocol to use.
- [in] dwMessageModes
Send and/or receive mode composed of a bitwise combination of one or more SMS Message Mode Constants values.
- [out] psmshHandle
SMS handle to use for subsequent SMS Service commands.
[in] phMessageAvailableEvent
Event handle that is signaled when a new message is available to read.Applications may wait on this handle by calling suitable Win32 APIs: WaitForSingleObject, MsgWaitForMultipleObjects, and so on), but should NOT use this handle with any other APIs (SetEvent, ResetEvent, and so on).
Return Value
HRESULT is S_OK for success, a standard error value, or one of the error constants defined in SMS Specific Errors.
Example
HRESULT hr = NOERROR;
SMS_HANDLE smshHandle;
SMS_ADDRESS smsaAddress;
const wchar_t * phoneNumber = L"+18005550111";
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
LPWSTR pwszTextData = L"This is a test";
SMS_MESSAGE_ID * psmsmidMessageID = NULL;
hr = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, &hMsgEvent );
smsaAddress.smsatAddressType = SMSAT_INTERNATIONAL;
wcsncpy_s( smsaAddress.ptsAddress, SMS_MAX_ADDRESS_LENGTH, phoneNumber, SMS_MAX_ADDRESS_LENGTH);
tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS1;
tpsd.psReplaceOption = PSRO_NONE;
// Send a message
hr = SmsSendMessage(
smshHandle
, 0
, &smsaAddress
, 0
, (BYTE*)(pwszTextData )
, wcslen( pwszTextData )*sizeof(WCHAR)
, (BYTE*)(&tpsd )
, sizeof( tpsd )
, SMSDE_OPTIMAL
, SMS_OPTION_DELIVERY_NONE
, psmsmidMessageID
);
hr = SmsClose( smshHandle );
Remarks
Multiple clients can open an SMS handle for sending a specific SMS message type, but only one client can have a handle open for reading at a time.
The event handle created by this function call should be waited on only-do not call any other event functions on this event handle.
Complete the use of the event handle by calling SmsClose. The behavior is undefined if the event is destroyed as an alternative to SmsClose.
Do not call CloseHandle on the phMessageAvailableEvent event handle; use SmsClose instead.
If the specified provider cannot support the requested action, an error is returned.
Requirements
Header |
sms.h |
Library |
sms.lib |
See Also
Reference
Short Message Service Functions
SMS Specific Errors
SmsClose
SMS Message Mode Constants
SMS Message Type Constants
Other Resources
WaitForSingleObject
MsgWaitForMultipleObjects
SetEvent
ResetEvent
CloseHandle