|
Add SMS Functionality To Your App
SMS Control Center includes a COM-API to send SMS. This makes it very
easy to add SMS functionality to your application. If you also like to receive
SMS in your app, you can add rules in SMS Control Center to execute your
application with command line options. In the end of this page you will find
download links to a sample in dotnet. Dotnet framework 2.0 is required.
Please note that SMS Control Center must be running for the SMS to be sent.
How to Send SMS
The SMS API includes two methods, one for
sending SMS and one for query the status for an SMS. Here is the code for
sending a SMS in C#
Parameters = new Object[3];
Parameters[0] = textBox1.Text; // Number
Parameters[1] = textBox2.Text; // Message text
Parameters[2] = false; // True if you like an delivery report
m_nItemID = (Int32) objApp_Late.GetType().InvokeMember("SendSMS",
BindingFlags.InvokeMethod, null, objApp_Late, Parameters);
To query for the status you can use the QueryStatus method. It returns a short
interger with a status code.
Parameters = new Object[1]; Parameters[0] = m_nItemID; // id
Int16 nStatus = (Int16) m_objApp_Late.GetType().InvokeMember("QueryStatus",
BindingFlags.InvokeMethod, null, m_objApp_Late, Parameters);
Return codes:
-1 = Invalid item id
1 = SMS in outbox
2 = SMS Sent
3 = SMS waiting to be executed
You can also use QueryStatus with m_nItemID = -1 to check if the mobile is connected to PC.
Send SMS from command line or VBScript
You can use the SMS API to send SMS from a VBScript and use this from the
command line.
Here is a simple example. Just copy and paste into a file with the extention
.VBS
Dim oApp
Set oApp = createobject("SmsCenter.Application")
oApp.SendSMS "0709999999", "Message Text", false
Set oApp = Nothing
Download
sample vbs-script
How to Receive SMS
First you need to add a rule in SMS Control Center to
start the application when an SMS is received. There are three macros:
$PHONE$
|
The senders phone number |
$NAME$ |
The senders name, if resolved |
$TEXT$ |
Message text |
When your application i started it's just to parse the input command line.
iIndexN = sCmdLine.IndexOf("/n");
iIndexM = sCmdLine.IndexOf("/m");
sNumber = sCmdLine.Substring(iIndexN + 2, iIndexM - iIndexN - 2); sMessage =
sCmdLine.Substring(iIndexM + 2);
This method will start a new instance of the executable each time a new SMS is
received. If you would like to handle the received SMS in one instance you can
use a mutex to check if another instance is running and just send the
information as a window message or save the information in a database.
bool bFirstInstance;
var mutex =
new Mutex(true,
"SCC Sample", out
bFirstInstance);
if (!bFirstInstance)
{
ProcessAgruments();
}
|
|