开始一个
MAPI Session
访问消息存储区之前,必须初始化
the MAPI subsystem
且记录一个
MAPI session.
从而获得
IMAPISession
接口对象的一个引用
,
通过此引用访问消息存储表,消息存储器,消息目录以及消息本身。
1.Increment the MAPI subsystem reference count, and initialize global data for the MAPI DLL with the MAPIInitialize global MAPI function, as follows:
hr = MAPIInitialize(NULL);
2.Log onto a MAPI session with the MAPILogonEx global MAPI function, and get a reference to an ICEMAPISession interface object:
hr = MAPILogonEx(0, NULL, NULL, 0, (LPMAPISESSION *)&pSession);
Code Example
:
HRESULT hr;
// ICEMAPISession
继承自
IMAPISession,
因为在
windows mobile
版本上开发,而不是
Desktop
版本上开发
,所以我们选择
ICEMAPISession.
ICEMAPISession * pSession = NULL;
hr = MAPIInitialize(NULL);
if (hr != S_OK) {
MessageBox(NULL, _T("MAPIInitialize failed."),_T("Warning"), MB_OK);
exit(0); //
用异常处理代替
}
hr = MAPILogonEx(0, NULL, NULL, 0, (LPMAPISESSION *)&pSession);
if (hr != S_OK) {
MessageBox(NULL, _T("MAPILogonEx failed."),_T("Warning"), MB_OK);
exit(0); // //
用异常处理代替
}