Introduction to cemapi (IV)-Sending Short Messages

Source: Internet
Author: User

Http://blog.csdn.net/depraved_survival/archive/2009/03/12/3980446.aspx

Cemapi Practice strategy (4) -- send short message by Wu chunlei QQ: 819543772 Email: wuchunlei@163.com

4. Send Short Messages

Worker Process. To put it simply, this process controls the process of receiving and sending text messages and emails in the background, and provides a display UI at the front end for you to operate on text messages. The text message sending part in this article is implemented by using tmail's text message sending function, without the need to directly use the AT command, which makes the code in the text message sending part very simple.

1. tmail.exe Process

A) The Listener is a tmail.exe process.

Tmail.exe is the core module for Microsoft to process messages, including text messages, outlook and other mail messages, as well as third-party custom MMS function modules. Feature. Most of the MMS features of wm5.0 and earlier versions are provided by third-party developers through the implementation of this COM interface. At last, we mentioned that the SMS interception program mapirule is essentially the processmessage method that implements the imapiclient interface and then registers it to the system. tmail loads this COM component at startup, this provides the SMS Interception Function.

B) whether the execute tmail.exe process is running

In many cases, we hope that we can know whether tmail.exe is currently running for subsequent operations. The producer cannot be sent out after it is started. For some time, we do not expect tmail.exeto run, such as when tmail.exe registers mapirule. To continue the content of this document, you must first determine whether the tmail.exeprocess is running. Although this part of content does not belong to the cemapi category, it is a necessary basis.

The worker process is no longer running. I directly gave this part of the source program and added comments and instructions on it. The program is very simple and easy to understand. You can also directly copy it for use, after all, this is not the focus of this article.

// The parameter is the full name of the process to be searched, for example, tmail.exe

// If 0 is returned, the process does not exist; otherwise, the process ID is returned.

DWORD findprocess (cstring strprocessname)

{

DWORD dwpid = 0; // The ID used to save tmail.exe

Handle hhandle = createconlhelp32snapshot (th32cs_snapprocess, 0); // create a snapshot for the current system process

DWORD dwid =: getcurrentprocessid (); // ID of the current process

If (invalue_handle_value! = Hhandle) // If the snapshot is created successfully

{

Processentry32 stentry;

Stentry. dwsize = sizeof (processentry32 );

If (process32first (hhandle, & stentry) // search for a process in the snapshot. stentry returns process-related attributes and information.

{

Do

{

If (wcsstr (stentry. szexefile, strprocessname) // compare whether the process name matches the strprocessname

{

If (dwid! = Stentry. th32processid) // if the process ID is equal and is not the same as the current process ID, find the process corresponding to strprocessname.

{

Dwpid = stentry. th32processid;

Break;

}

}

} While (process32next (hhandle, & stentry); // search for the next process in the snapshot.

}

Closetoolhelp32snapshot (hhandle); // release the snapshot handle.

}

Return dwpid;

}

 

The program is easy to understand. It should be noted that the createconlhelp32snapshot function must contain the tlhelp32.h header file and add the toolhelp. Lib library file.

C) Kill the tmail.exe Process

After obtaining the process ID, it is easy to kill the process. The Code is as follows:

DWORD dwpid1_findprocess(_t(“tmail.exe "));

If (0! = Dwpid) {// find the process

Handle hhandle = OpenProcess (process_terminate, false, dwpid); // obtain the tmail.exe handle in the process ID.

Terminateprocess (hhandle, 0); // close the process

}

D) Start the tmail.exe process.

Directly call the CreateProcess function to start the process. The Code is as follows:

// Start the tmail.exe Process

CreateProcess (_ T ("tmail.exe"), _ T ("-runinbkg"), null, null, false, 0, null );

Run the command line parameter -runinbkgand unzip tmail.exe directly in the background to avoid the appearance of the text message mail browser. In addition, tmail.exe also has many useful command line parameters, which are listed below. (This part of content is introduced on many websites, but since I first saw it in the boring articles, only the reference from bored customers is shown here 《MapiSome questions(Bored customers))

-Service: Call type, MMS or SMS

-Attach: add an attachment.

-Subject: add subject

-To: add the target address

2. Use tmail.exe to send a short message

The previous sections have discussed in detail how to create a short message in a specific mailbox. In fact, a short message is created, and 95% of the content in the text message sending function has been completed. Here, we only introduce one method, iMessage: submitmessageproducer, which is used to submit created short messages like tmail.exe, and tmail completes the text message sending process. The method is defined as follows:

Hresult imesssage: submitmessage (ulong ulflag );

The return value is only used to determine whether the method is correctly executed. Parameter List:

Ulflag: indicates the sending flag. The optional values include force_submit and 0. Generally, the value 0 is selected in the text message application. I added the force_submit flag, which makes no difference, it is estimated that it should be used in a specific environment.

The code used to send text messages is basically the same as that used to create messages. You can refer to the code. The only difference is that the last m_pmsg-> savechange (0) replace this sentence with m_pmsg-> subjectmessage (0.

4. How to block the system prompts after the text message is sent

After each message is sent, a prompt box is displayed, prompting that the message has been sent. If we develop our own applications and do not want to send every message, the prompt box will show your face. What if we shield the system prompt information after the text message is sent? In fact, this Part has nothing to do with cemapi, but write it here for the sake of system as much as possible.

Choose Start> program> Microsoft Visual Studio 2005> Visual Studio remote tools on the Windows (PC-side) menu to start Remote Registry Editor ", create a settings directory under the HKEY_LOCAL_MACHINE/software/Microsoft/inbox directory and add a DWORD key named smsnosentmsg with a value of 1. Restart the device or the simulator.

5. source program

After the article is written, sort it out and try again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.