Re: MAPIInitialize failed and get an error message

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

First of all, I am sorry I did not reply it until now. The reason is I am
not able to login to hotmail.

Yes. you are right. It is working now. Thank you so much.

One more question:
Now I just dynamically load library for MAPIInitialize, MAPIUninitialize,
MAPILogonEx, MAPIAllocateBuffer and MAPIFreeBuffer.

I still leave HrQueryAllRows and FreeProws to rely on mapi32.lib. (it will
crash if I do the same as MAPIInitialize,MAPIUninitialize...)

Do you think it is OK?

At the end, thank you so much for your help again.

Have a good day.

Yours,
Michael

"Dmitry Streblechenko" wrote:

The error is MAPI_E_LOGON_FAILED
Since you are not supplying the profile name, add the MAPI_USE_DEFAULT bit.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"zhanglr" <zhanglr@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:845A9ECE-D857-4563-86F3-97297C241DA0@xxxxxxxxxxxxxxxx
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

"Dmitry Streblechenko" wrote:

Your function definition is wrong. Specify the STDAPICALLTYPE calling
convention.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"zhanglr" <zhanglr@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C44F3F7F-C026-445D-8CB2-F90CF468F444@xxxxxxxxxxxxxxxx
Hi 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?

------------------------------------------------------------------
BTW, the following is the code:

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

"Dmitry Streblechenko" wrote:

You 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

"zhanglr" <zhanglr@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3B1745A6-AF7F-4409-A9C3-162EA624FDBB@xxxxxxxxxxxxxxxx
Hi,

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.

BTW, my pc setting is:
OS is Vista.
IDE is Microsoft Visual Studio 2005
email client:
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









.


Quantcast