Offline State Sample
There have been questions lately on the MAPI mailing list about how to get the connection state API working. Particularly the HrOpenOfflineObj and Advise calls. Since I had a partial sample already sitting here I figured I whip it into shape and publish it.
I'll refer most questions of implementation to the sample code itself. One thing does need to be called out though: This API only works in process. The only intended clients of this API are MAPI providers, COM Add-Ins, and Exchange Client Extensions. If your code is not running inside Outlook.exe, expect HrOpenOfflineObj to return MAPI_E_NOT_FOUND. This point is not made clear in the published documentation.
I've implemented this sample as a Com Add-In. When loaded, an "Offline State" menu will appear. Through this menu, you can enable/disable state monitoring, check the current state, and change the current state. A lot of the output for the sample is through OutputDebugString, so run under the debugger or use a debug monitor to watch it. It also writes a log file to c:offstate.txt.
The sample should compile in VC6 or VS 2003. I haven't tested it with VS 2005 yet, but it ought to work there as well.
Here's the download link: https://stephengriffin.members.winisp.net/OfflineStateAddIn/OfflineStateAddIn.zip
Thanks to JasonJoh for writing some of the UI that I didn't feel like writing, and thanks to Shawn Walker for providing the impetus for fixing up and publishing the sample in the first place.
[11/11/05] Fixed sample URL
Comments
- Anonymous
May 02, 2006
Steve, thanks for the sample. Below are the steps I'm taking to prevent a user from switching to Offline mode. Is this the right approach? Is there a better way?
1. Subscribe to Notifications
2. In the STATECHANGE_DONE notification, depending on the ulStateOld, I call pOffline->SetCurrentState with MAPIOFFLINE_FLAG_DEFAULT ( to prevent the deadlock that would occur if I use MAPIOFFLINE_FLAG_BLOCK ) to reset the connection state to Online.
Thanks!
Lev