Quick Messaging API (MAPI) Sample

I heard someone say they wished it were possible to create a speed dial entry for text messaging in Windows Mobile. As most of you might know, text messaging is not a standalone app - it's just another account within the Messaging client, which also supports Outlook and other email accounts (Hotmail, POP3 etc).

So how do you create a speed dial entry that always goes directly into Text Messages (and not any of the other types of messaging accounts?)

I decided to write a tiny app that does this. My first thought was to launch a command line like Inbox.exe with some special parameter that would force it into the Text Messages account. The downside of doing something like that is the .exe name/path might change in the future and the command line parameter is probably undocumented.

I then remembered reading about some APIs that let you interact with the messaging client. I found one that did exactly what I needed: MailSwitchToAccount.

Sweet! With this documented API, the task becomes very easy and immune from breaking in future versions of Windows Mobile. The entire program is as follows:

#include <windows.h>
#include <cemapi.h>

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
    MailSwitchToAccount(_T("SMS"), MCF_ACCOUNT_IS_NAME);
    return 0;
}

As you can see, it is very easy to write an app that launches a specific account within the Messaging app. The user can then create a shortcut to this app and launch it from speed dial or the Start menu. For more MAPI functions that might be useful to you, click here. (Note: you will need to link with cemapi.lib to use these functions).

-Mel Sampat