Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MAPIInitialize fails in Thread Environment.

5 views
Skip to first unread message

miztaken

unread,
Feb 27, 2008, 7:18:38 AM2/27/08
to
Hi,
It now i have been creating a managed wrapper for mapi32.dll in VC++.NET
2005.

Then i was consuming the managed dll in my C#.application.

Everything was working fine but as i wanted to deal with multiple PST at a
time so i made the Application (C#) threaded.
But no soon i called the API of my managed DLL in thread,
MAPIInitialize(NULL) failed and returned the error code -2147417850.

I am trying to initialize mapi inside thread, for each thread.

What can be wrong:-
My VC++ wrapper project has following properties:
Common Language Runtime Support, Old Syntax (/clr:oldSyntax)
Multi-threaded Debug DLL (/MDd)

where am i wrong.. please help me

Thank You
miztaken


SvenC

unread,
Mar 17, 2008, 5:09:19 AM3/17/08
to
Hi miztaken,

> It now i have been creating a managed wrapper for mapi32.dll in
> VC++.NET 2005.
>
> Then i was consuming the managed dll in my C#.application.
>
> Everything was working fine but as i wanted to deal with multiple PST
> at a time so i made the Application (C#) threaded.
> But no soon i called the API of my managed DLL in thread,
> MAPIInitialize(NULL) failed and returned the error code -2147417850.
>
> I am trying to initialize mapi inside thread, for each thread.

Make sure you are creating STA threads, i.e. apartment threaded threads.
Thread t = new Thread(...);
t.ApartmentState = ApartmentState.STA;
t.Start();

Call MAPIInitialize only once per thread at the beginning of the
thread function.

--
SvenC

0 new messages