Hi Dmitry,
Yes. MAPIInitialize and MAPIUninitialize are working now after I add
STDAPICALLTYPE.
But I get another error when I call MAPILogonEx:
-- 0x80040111 ( ClassFactory cannot supply required class )
Would you please tell me how to solve it?
BTW, do you know where I am able to find a sample of MAPI? I have downloaded
one from microsoft -- Platform SDK Archive Samples: MAPI Samples. But it also
links mapi32.lib.
At the end, thanks again for your help.
----------------------------------------------------
typedef HRESULT (STDAPICALLTYPE *MSMAPIInitialize)(LPVOID);
typedef void (STDAPICALLTYPE *MSMAPIUninitialize)(VOID);
typedef HRESULT (STDAPICALLTYPE *MSMAPILogonEx)(ULONG, LPTSTR, LPTSTR,
FLAGS, LPMAPISESSION FAR *);
void CTestDlg::OnBnClickedButton19()
{
HMODULE hLib = NULL;
if(hLib = LoadLibrary (_T("msmapi32.dll")))
{
MSMAPIInitialize fMAPIInitialize = NULL;
MSMAPIUninitialize fMAPIUninitialize = NULL;
MSMAPILogonEx fMAPILogonEx = NULL;
CComPtr<IMAPISession> pSession = NULL;
if ( (fMAPIInitialize = (MSMAPIInitialize)GetProcAddress (hLib,
"MAPIInitialize"))
&& (fMAPIUninitialize = (MSMAPIUninitialize)GetProcAddress (hLib,
"MAPIUninitialize"))
&& (fMAPILogonEx = (MSMAPILogonEx)GetProcAddress (hLib, "MAPILogonEx")) )
{
HRESULT hRs = fMAPIInitialize( NULL );
hRs = fMAPILogonEx( 0, NULL, NULL,
MAPI_EXTENDED | MAPI_NEW_SESSION | MAPI_UNICODE,
&pSession );
fMAPIUninitialize();
}
FreeLibrary(hLib);
}
}
Best Regards,
Michael
Post by Dmitry StreblechenkoYour function definition is wrong. Specify the STDAPICALLTYPE calling
convention.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Post by zhanglrHi Dmitry,
First of all, thank you for your reply.
I try to load msmapi32.dll but when I call the function MAPIInitialize, I
got following error message
-- Run-Time Check Failure #0- The value of ESP was not properly saved
across a function call. This is usually a result of calling a function
declared with one calling convention with a function pointer declared with a
different calling convention.
Would you please tell me how to solve this problem?
------------------------------------------------------------------
typedef HRESULT (*MSMAPIInitialize)(LPVOID);
typedef void (*MSMAPIUninitialize)(VOID);
void CTestDlg::OnBnClickedButton19()
{
HMODULE hLib = NULL;
if(hLib = LoadLibrary (_T("msmapi32.dll")))
{
MSMAPIInitialize fMAPIInitialize = NULL;
MSMAPIUninitialize fMAPIUninitialize = NULL;
if ( (fMAPIInitialize = (MSMAPIInitialize)GetProcAddress (hLib,
"MAPIInitialize"))
&& (fMAPIUninitialize = (MSMAPIUninitialize)GetProcAddress (hLib,
"MAPIUninitialize")) )
{
fMAPIInitialize( NULL );
fMAPIUninitialize();
}
FreeLibrary(hLib);
}
}
Best Regards
Post by Dmitry StreblechenkoYou are loading a wrong mapi dll. How exactly do you link the MAPIInitialize
function? You need to call LoadLibrary instead of statically linking., The
right dll is msmapi32.dll in Program Files.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Post by zhanglrHi,
I get following error message when I call MAPIInitialize( NULL );
-- Either there is no default mail client or the current mail client cannot
fulfill the messaging request. Please run Microsoft Office Outlook and
set
it
as the default mail client.
OS is Vista.
IDE is Microsoft Visual Studio 2005
1) outlook 2003 (no default)
2) Windows mail (default email client) -- I manually set it as default
email client.
(1. Click to open Set Program Access and Computer Defaults.? If you are
prompted for an administrator password or confirmation, type the
password
or
provide confirmation.
2. Under Choose a configuration, click Custom.
3. Under Choose a default e-mail program, click the e-mail program you'd
like to use, and then click OK.)
Best Regards,
Michael