PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Program Addins C# Error when calling MAPI.Session.Logon()

Reply

C# Error when calling MAPI.Session.Logon()

 
Thread Tools Rate Thread
Old 17-07-2008, 02:26 PM   #1
Johan Machielse
Guest
 
Posts: n/a
Default C# Error when calling MAPI.Session.Logon()


Dear reader,

See next piece of code (written in C#):

MAPI.Session mapiSession = new MAPI.Session();
mapiSession.Logon(null, null, false, false, 0, false, "");

The call mapiSession.Logon() throws the following exception:
[Collaboration Data Objects - [E_INVALIDARG(80070057)]

What can I do to solve this problem; which arguments do I have to pass?

Thank you in advance,

Johan Machielse
Avanade


  Reply With Quote
Old 17-07-2008, 06:30 PM   #2
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

First of all CDO 1.21 is not supported for use with any managed code, so if
it doesn't work then you won't get any help.

That said, you could try using null strings instead of null for the first 2
arguments to Logon().

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Johan Machielse" <Johan Machielse@discussions.microsoft.com> wrote in
message news:4637558F-7719-4B9F-BBFC-995F8AFDEF4C@microsoft.com...
> Dear reader,
>
> See next piece of code (written in C#):
>
> MAPI.Session mapiSession = new MAPI.Session();
> mapiSession.Logon(null, null, false, false, 0, false, "");
>
> The call mapiSession.Logon() throws the following exception:
> [Collaboration Data Objects - [E_INVALIDARG(80070057)]
>
> What can I do to solve this problem; which arguments do I have to pass?
>
> Thank you in advance,
>
> Johan Machielse
> Avanade
>
>


  Reply With Quote
Old 17-07-2008, 08:00 PM   #3
Johan Machielse
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

Ken,

thank you for your quick answer, but now if you want to create an add-in for
Outlook 2003/2007 which changes the color labels of the appointments in a
calendar, what is than the best way to solve this (I want to use .NET to
create the plug-in, but CDO 1.21 is not supported...)?

Thank you in advance,

Johan Machielse
Avanade



"Ken Slovak - [MVP - Outlook]" wrote:

> First of all CDO 1.21 is not supported for use with any managed code, so if
> it doesn't work then you won't get any help.
>
> That said, you could try using null strings instead of null for the first 2
> arguments to Logon().
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Johan Machielse" <Johan Machielse@discussions.microsoft.com> wrote in
> message news:4637558F-7719-4B9F-BBFC-995F8AFDEF4C@microsoft.com...
> > Dear reader,
> >
> > See next piece of code (written in C#):
> >
> > MAPI.Session mapiSession = new MAPI.Session();
> > mapiSession.Logon(null, null, false, false, 0, false, "");
> >
> > The call mapiSession.Logon() throws the following exception:
> > [Collaboration Data Objects - [E_INVALIDARG(80070057)]
> >
> > What can I do to solve this problem; which arguments do I have to pass?
> >
> > Thank you in advance,
> >
> > Johan Machielse
> > Avanade
> >
> >

>
>

  Reply With Quote
Old 18-07-2008, 01:11 AM   #4
Dmitry Streblechenko
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

Or, better yet, set Session.MAPIOBJECT property to Namespace.MAPIOBJECT from
OOM to make sure CDO 1.21 and Outlook share the same MAPI session.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Ken Slovak - [MVP - Outlook]" <kenslovak@mvps.org> wrote in message
news:OA8UGMD6IHA.5012@TK2MSFTNGP02.phx.gbl...
> First of all CDO 1.21 is not supported for use with any managed code, so
> if it doesn't work then you won't get any help.
>
> That said, you could try using null strings instead of null for the first
> 2 arguments to Logon().
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Johan Machielse" <Johan Machielse@discussions.microsoft.com> wrote in
> message news:4637558F-7719-4B9F-BBFC-995F8AFDEF4C@microsoft.com...
>> Dear reader,
>>
>> See next piece of code (written in C#):
>>
>> MAPI.Session mapiSession = new MAPI.Session();
>> mapiSession.Logon(null, null, false, false, 0, false, "");
>>
>> The call mapiSession.Logon() throws the following exception:
>> [Collaboration Data Objects - [E_INVALIDARG(80070057)]
>>
>> What can I do to solve this problem; which arguments do I have to pass?
>>
>> Thank you in advance,
>>
>> Johan Machielse
>> Avanade
>>
>>

>



  Reply With Quote
Old 18-07-2008, 01:13 AM   #5
Dmitry Streblechenko
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

Outlook 2007 exposes AppointmentItem.PropertyAccessor object that lets you
set MAPI properties.
In the older versions of Outlook you will need to use Extended MAPI or CDO
1.21 (neither is supported in .Net) or <plug> Redemption (url below) </plug>

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Johan Machielse" <JohanMachielse@discussions.microsoft.com> wrote in
message news:08F65DC7-247F-4DFB-A7B4-0EC64B3F1D89@microsoft.com...
> Ken,
>
> thank you for your quick answer, but now if you want to create an add-in
> for
> Outlook 2003/2007 which changes the color labels of the appointments in a
> calendar, what is than the best way to solve this (I want to use .NET to
> create the plug-in, but CDO 1.21 is not supported...)?
>
> Thank you in advance,
>
> Johan Machielse
> Avanade
>
>
>
> "Ken Slovak - [MVP - Outlook]" wrote:
>
>> First of all CDO 1.21 is not supported for use with any managed code, so
>> if
>> it doesn't work then you won't get any help.
>>
>> That said, you could try using null strings instead of null for the first
>> 2
>> arguments to Logon().
>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm
>>
>>
>> "Johan Machielse" <Johan Machielse@discussions.microsoft.com> wrote in
>> message news:4637558F-7719-4B9F-BBFC-995F8AFDEF4C@microsoft.com...
>> > Dear reader,
>> >
>> > See next piece of code (written in C#):
>> >
>> > MAPI.Session mapiSession = new MAPI.Session();
>> > mapiSession.Logon(null, null, false, false, 0, false, "");
>> >
>> > The call mapiSession.Logon() throws the following exception:
>> > [Collaboration Data Objects - [E_INVALIDARG(80070057)]
>> >
>> > What can I do to solve this problem; which arguments do I have to pass?
>> >
>> > Thank you in advance,
>> >
>> > Johan Machielse
>> > Avanade
>> >
>> >

>>
>>



  Reply With Quote
Old 18-07-2008, 10:40 AM   #6
Johan Machielse
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

Hi Ken,

I figured out what how the Logon method has to be called:

mapiSession.Logon("Default Outlook Profile",
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value);
It works!

Regards,

Johan Machielse
Avanade

"Ken Slovak - [MVP - Outlook]" wrote:

> First of all CDO 1.21 is not supported for use with any managed code, so if
> it doesn't work then you won't get any help.
>
> That said, you could try using null strings instead of null for the first 2
> arguments to Logon().
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Johan Machielse" <Johan Machielse@discussions.microsoft.com> wrote in
> message news:4637558F-7719-4B9F-BBFC-995F8AFDEF4C@microsoft.com...
> > Dear reader,
> >
> > See next piece of code (written in C#):
> >
> > MAPI.Session mapiSession = new MAPI.Session();
> > mapiSession.Logon(null, null, false, false, 0, false, "");
> >
> > The call mapiSession.Logon() throws the following exception:
> > [Collaboration Data Objects - [E_INVALIDARG(80070057)]
> >
> > What can I do to solve this problem; which arguments do I have to pass?
> >
> > Thank you in advance,
> >
> > Johan Machielse
> > Avanade
> >
> >

>
>

  Reply With Quote
Old 18-07-2008, 01:57 PM   #7
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

You seem to have it solved now, but for things like that I use the
Redemption library that Dmitry mentioned in his post. It does everything CDO
did and a whole lot more.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Johan Machielse" <JohanMachielse@discussions.microsoft.com> wrote in
message news:08F65DC7-247F-4DFB-A7B4-0EC64B3F1D89@microsoft.com...
> Ken,
>
> thank you for your quick answer, but now if you want to create an add-in
> for
> Outlook 2003/2007 which changes the color labels of the appointments in a
> calendar, what is than the best way to solve this (I want to use .NET to
> create the plug-in, but CDO 1.21 is not supported...)?
>
> Thank you in advance,
>
> Johan Machielse
> Avanade


  Reply With Quote
Old 18-07-2008, 06:28 PM   #8
Dmitry Streblechenko
Guest
 
Posts: n/a
Default Re: C# Error when calling MAPI.Session.Logon()

That will break if the user has more than one profile and a non-default
profiel is used.
Setting the MAPIOBJECT property (Outlook 2002 and up) will work much better.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Johan Machielse" <JohanMachielse@discussions.microsoft.com> wrote in
message news:2091F598-22ED-41B9-9094-BF0DF806BF71@microsoft.com...
> Hi Ken,
>
> I figured out what how the Logon method has to be called:
>
> mapiSession.Logon("Default Outlook Profile",
> System.Reflection.Missing.Value,
> System.Reflection.Missing.Value,
> System.Reflection.Missing.Value,
> System.Reflection.Missing.Value,
> System.Reflection.Missing.Value,
> System.Reflection.Missing.Value);
> It works!
>
> Regards,
>
> Johan Machielse
> Avanade
>
> "Ken Slovak - [MVP - Outlook]" wrote:
>
>> First of all CDO 1.21 is not supported for use with any managed code, so
>> if
>> it doesn't work then you won't get any help.
>>
>> That said, you could try using null strings instead of null for the first
>> 2
>> arguments to Logon().
>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm
>>
>>
>> "Johan Machielse" <Johan Machielse@discussions.microsoft.com> wrote in
>> message news:4637558F-7719-4B9F-BBFC-995F8AFDEF4C@microsoft.com...
>> > Dear reader,
>> >
>> > See next piece of code (written in C#):
>> >
>> > MAPI.Session mapiSession = new MAPI.Session();
>> > mapiSession.Logon(null, null, false, false, 0, false, "");
>> >
>> > The call mapiSession.Logon() throws the following exception:
>> > [Collaboration Data Objects - [E_INVALIDARG(80070057)]
>> >
>> > What can I do to solve this problem; which arguments do I have to pass?
>> >
>> > Thank you in advance,
>> >
>> > Johan Machielse
>> > Avanade
>> >
>> >

>>
>>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off