1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_shell.hxx"
24 #include "sysmapi.hxx"
25 
26 #include <string>
27 #include <stdexcept>
28 
29 namespace shell
30 {
31 
WinSysMapi()32 WinSysMapi::WinSysMapi() :
33     m_lpfnMapiLogon(NULL),
34     m_lpfnMapiLogoff(NULL),
35     m_lpfnMapiSendMail(NULL)
36 {
37     m_hMapiDll = LoadLibrary("mapi32.dll");
38     if ((m_hMapiDll == INVALID_HANDLE_VALUE) || (m_hMapiDll == NULL))
39         throw std::runtime_error("Couldn't load MAPI library");
40 
41     m_lpfnMapiLogon = reinterpret_cast<LPMAPILOGON>(GetProcAddress(m_hMapiDll, "MAPILogon"));
42     if (!m_lpfnMapiLogon)
43         throw std::runtime_error("Couldn't find method MAPILogon");
44 
45     m_lpfnMapiLogoff = reinterpret_cast<LPMAPILOGOFF>(GetProcAddress(m_hMapiDll, "MAPILogoff"));
46     if (!m_lpfnMapiLogoff)
47         throw std::runtime_error("Couldn't find method MAPILogoff");
48 
49     m_lpfnMapiSendMail = reinterpret_cast<LPMAPISENDMAIL>(GetProcAddress(m_hMapiDll, "MAPISendMail"));
50     if (!m_lpfnMapiSendMail)
51         throw std::runtime_error("Couldn't find method MAPISendMail");
52 }
53 
~WinSysMapi()54 WinSysMapi::~WinSysMapi()
55 {
56     FreeLibrary(m_hMapiDll);
57 }
58 
MAPILogon(ULONG ulUIParam,LPTSTR lpszProfileName,LPTSTR lpszPassword,FLAGS flFlags,ULONG ulReserved,LPLHANDLE lplhSession)59 ULONG WinSysMapi::MAPILogon(
60     ULONG ulUIParam,
61     LPTSTR lpszProfileName,
62     LPTSTR lpszPassword,
63     FLAGS flFlags,
64     ULONG ulReserved,
65     LPLHANDLE lplhSession )
66 {
67     return m_lpfnMapiLogon(
68         ulUIParam,
69         lpszProfileName,
70         lpszPassword,
71         flFlags,
72         ulReserved,
73         lplhSession );
74 }
75 
MAPILogoff(LHANDLE lhSession,ULONG ulUIParam,FLAGS flFlags,ULONG ulReserved)76 ULONG WinSysMapi::MAPILogoff(
77     LHANDLE lhSession,
78     ULONG ulUIParam,
79     FLAGS flFlags,
80     ULONG ulReserved )
81 {
82     return m_lpfnMapiLogoff(lhSession, ulUIParam, flFlags, ulReserved);
83 }
84 
MAPISendMail(LHANDLE lhSession,ULONG ulUIParam,lpMapiMessage lpMessage,FLAGS flFlags,ULONG ulReserved)85 ULONG WinSysMapi::MAPISendMail(
86     LHANDLE lhSession,
87     ULONG ulUIParam,
88     lpMapiMessage lpMessage,
89     FLAGS flFlags,
90     ULONG ulReserved )
91 {
92     return m_lpfnMapiSendMail(lhSession, ulUIParam, lpMessage, flFlags, ulReserved);
93 }
94 
95 }
96 
97