SimWriteMessage (Compact 2013)

3/26/2014

This function writes a Short Message Service (SMS) message to a particular storage location.

Note

Short Message Service (SMS) messages are always written to the first available storage location.

Syntax

HRESULT SimWriteMessage (
  HSIM hSim,
  DWORD dwStorage,
  LPDWORD lpdwIndex,
  LPSIMMESSAGE lpSimMessage
);

Parameters

  • [in] hSim
    Points to a valid HSIM handle.
  • [out] lpdwIndex
    Set to the index where the message was written.
  • [in,out] lpSimMessage
    Points to a SIMMESSAGE structure.

Return Value

HRESULT is S_OK for success, or one of the SIM_E error constants defined in the SIM Manager Error Constants table.

Example

HRESULT    hr;
SIMMESSAGE sm;
HSIM       hSim;
DWORD      dwStorage;
DWORD      dwMessageIndex;

memset( &sm, 0, sizeof( sm ) );
sm.cbSize =     sizeof( sm );

hr = SimInitialize( SIM_INIT_NONE, NULL, 0, &hSim );

sm.dwParams
= SIM_PARAM_MSG_ADDRESS
& SIM_PARAM_MSG_ADDRESS_TYPE
& SIM_PARAM_MSG_NUMPLAN
& SIM_PARAM_MSG_HEADER
& SIM_PARAM_MSG_HEADER_LENGTH
& SIM_PARAM_MSG_MESSAGE ;

sm.cbHdrLength   = 8;
sm.dwAddressType = SIM_ADDRTYPE_INTERNATIONAL;
sm.dwNumPlan     = SIM_NUMPLAN_TELEPHONE;

memcpy( sm.rgbHeader  ,     "header01", 8 );
memcpy( sm.lpszAddress, _T( "12345550111\0" ), MAX_LENGTH_ADDRESS );
memcpy( sm.lpszMessage, _T( "My message.\0" ), MAX_LENGTH_MESSAGE );

dwStorage = SIM_SMSSTORAGE_SIM;

hr = SimWriteMessage ( hSim, dwStorage, &dwMessageIndex, &sm );

// Finished using the SIM Manager
hr = SimDeinitialize( hSim );

Remarks

The SIMMESSAGE structure pointed to by lpSimMessage must be first populated with the following data elements:

  1. cbSize
  2. dwParams
  3. lpszAddress
  4. dwAddressType
  5. dwNumPlan
  6. cbHdrLength
  7. lpszMessage

The stReceiveTime parameter need not be initialized, as it is populated by SimWriteMessage.

The minimum parameters required correspond to this list of bits in the dwParams parameter of the SIMMESSAGE structure:

  • SIM_PARAM_MSG_ADDRESS
  • SIM_PARAM_MSG_ADDRESS_TYPE
  • SIM_PARAM_MSG_NUMPLAN
  • SIM_PARAM_MSG_MESSAGE

These are defined in the header file as the constant: REQUIRED_WRITE_PARAMS.

When specifying a header, all of the following must be true:

  • cbHdrLength must be equal to the byte length of the header data in rgbHeader,
  • rgbHeader must contain header data of length equal to cbHdrLength,
  • SIM_PARAM_MSG_HEADER must be set in the dwParams field of lpSimMessage,
  • SIM_PARAM_MSG_HEADER_LENGTH must be set in the dwParams field of lpSimMessage.

When not specifying a header, you can set SIM_PARAM_MSG_HEADER_LENGTH and specify cbHdrLength; In this case the cbHdrLength value must be zero.

When not specifying a header and you do not set SIM_PARAM_MSG_HEADER_LENGTH, the value of cbHdrLength is ignored.

SIM_NOTIFY_MSG_STORED is received when this function executes successfully. Callback functions registered with SimInitialize are called with SIM_NOTIFY_MSG_STORED.

Requirements

Header

simmgr.h

Library

sim.lib

See Also

Reference

SIM Manager Functions
SimInitialize
SimReadMessage
SIM Manager SMS Storage Constants
SIM Manager Notifications
SIMMESSAGE