From: Groghz on
Hi,

I'm pinvoking a mapi function in c#

[DllImport("cemapi.dll", SetLastError = true)]
public static extern int MailSwitchToAccount(string pszAccount,
UInt32 dwFlags);

I then call the function :

if (Mapi.MailSwitchToAccount("My_account",
Mapi.MCF_ACCOUNT_IS_NAME | Mapi.MCF_RUN_IN_BACKGROUND) != 0)
{
int err = Marshal.GetLastWin32Error();
Win32Exception ex = new Win32Exception(err);
Log("mapi", Severity.Error, "MailSwitchToAccount()
failed with win32error=" + ex.NativeErrorCode + ", ex.Message=" +
ex.Message);
}

The problem is MailSwitchToAccount never returns 0, and so a the error
handling code is executed. In the logs, the ex.NativeErrorCode is
always 0, which doesn't seem to be a valid error code.

Is there another way to find the error code ?

regards,

manu

From: Peter Foot [MVP] on
Since MailSwitchToAccount is a WM5.0 API, and you are using managed code,
why not use the managed equivalent in the WM5.0 SDK -
Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.SwitchToAccount

With regards your query, if you want to know what the error code is you need
to look at the integer return value from MailSwitchToAccount.

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

<Groghz(a)gmail.com> wrote in message
news:1161792507.141590.146590(a)i42g2000cwa.googlegroups.com...
> Hi,
>
> I'm pinvoking a mapi function in c#
>
> [DllImport("cemapi.dll", SetLastError = true)]
> public static extern int MailSwitchToAccount(string pszAccount,
> UInt32 dwFlags);
>
> I then call the function :
>
> if (Mapi.MailSwitchToAccount("My_account",
> Mapi.MCF_ACCOUNT_IS_NAME | Mapi.MCF_RUN_IN_BACKGROUND) != 0)
> {
> int err = Marshal.GetLastWin32Error();
> Win32Exception ex = new Win32Exception(err);
> Log("mapi", Severity.Error, "MailSwitchToAccount()
> failed with win32error=" + ex.NativeErrorCode + ", ex.Message=" +
> ex.Message);
> }
>
> The problem is MailSwitchToAccount never returns 0, and so a the error
> handling code is executed. In the logs, the ex.NativeErrorCode is
> always 0, which doesn't seem to be a valid error code.
>
> Is there another way to find the error code ?
>
> regards,
>
> manu
>

From: Groghz on
I didn't know this dll ;)

I'll give it a try !

Thanks !

Peter Foot [MVP] a écrit :

> Since MailSwitchToAccount is a WM5.0 API, and you are using managed code,
> why not use the managed equivalent in the WM5.0 SDK -
> Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.SwitchToAccount
>
> With regards your query, if you want to know what the error code is you need
> to look at the integer return value from MailSwitchToAccount.
>
> Peter
>
> --
> Peter Foot
> Device Application Development MVP
> www.peterfoot.net | www.inthehand.com
>
> <Groghz(a)gmail.com> wrote in message
> news:1161792507.141590.146590(a)i42g2000cwa.googlegroups.com...
> > Hi,
> >
> > I'm pinvoking a mapi function in c#
> >
> > [DllImport("cemapi.dll", SetLastError = true)]
> > public static extern int MailSwitchToAccount(string pszAccount,
> > UInt32 dwFlags);
> >
> > I then call the function :
> >
> > if (Mapi.MailSwitchToAccount("My_account",
> > Mapi.MCF_ACCOUNT_IS_NAME | Mapi.MCF_RUN_IN_BACKGROUND) != 0)
> > {
> > int err = Marshal.GetLastWin32Error();
> > Win32Exception ex = new Win32Exception(err);
> > Log("mapi", Severity.Error, "MailSwitchToAccount()
> > failed with win32error=" + ex.NativeErrorCode + ", ex.Message=" +
> > ex.Message);
> > }
> >
> > The problem is MailSwitchToAccount never returns 0, and so a the error
> > handling code is executed. In the logs, the ex.NativeErrorCode is
> > always 0, which doesn't seem to be a valid error code.
> >
> > Is there another way to find the error code ?
> >
> > regards,
> >
> > manu
> >

From: Groghz on
The
Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.SwitchToAccount
works fine.

But the switching is done in foreground : PocketOutlook opens and
switch the account. It's disturbing for the user.

Could the switching be done in background ?

regards,

manu


Groghz(a)gmail.com a écrit :

> I didn't know this dll ;)
>
> I'll give it a try !
>
> Thanks !
>
> Peter Foot [MVP] a écrit :
>
> > Since MailSwitchToAccount is a WM5.0 API, and you are using managed code,
> > why not use the managed equivalent in the WM5.0 SDK -
> > Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.SwitchToAccount
> >
> > With regards your query, if you want to know what the error code is you need
> > to look at the integer return value from MailSwitchToAccount.
> >
> > Peter
> >
> > --
> > Peter Foot
> > Device Application Development MVP
> > www.peterfoot.net | www.inthehand.com
> >
> > <Groghz(a)gmail.com> wrote in message
> > news:1161792507.141590.146590(a)i42g2000cwa.googlegroups.com...
> > > Hi,
> > >
> > > I'm pinvoking a mapi function in c#
> > >
> > > [DllImport("cemapi.dll", SetLastError = true)]
> > > public static extern int MailSwitchToAccount(string pszAccount,
> > > UInt32 dwFlags);
> > >
> > > I then call the function :
> > >
> > > if (Mapi.MailSwitchToAccount("My_account",
> > > Mapi.MCF_ACCOUNT_IS_NAME | Mapi.MCF_RUN_IN_BACKGROUND) != 0)
> > > {
> > > int err = Marshal.GetLastWin32Error();
> > > Win32Exception ex = new Win32Exception(err);
> > > Log("mapi", Severity.Error, "MailSwitchToAccount()
> > > failed with win32error=" + ex.NativeErrorCode + ", ex.Message=" +
> > > ex.Message);
> > > }
> > >
> > > The problem is MailSwitchToAccount never returns 0, and so a the error
> > > handling code is executed. In the logs, the ex.NativeErrorCode is
> > > always 0, which doesn't seem to be a valid error code.
> > >
> > > Is there another way to find the error code ?
> > >
> > > regards,
> > >
> > > manu
> > >

From: Groghz on
No it can't be done in bg

Groghz(a)gmail.com a écrit :

> The
> Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.SwitchToAccount
> works fine.
>
> But the switching is done in foreground : PocketOutlook opens and
> switch the account. It's disturbing for the user.
>
> Could the switching be done in background ?
>
> regards,
>
> manu
>
>
> Groghz(a)gmail.com a écrit :
>
> > I didn't know this dll ;)
> >
> > I'll give it a try !
> >
> > Thanks !
> >
> > Peter Foot [MVP] a écrit :
> >
> > > Since MailSwitchToAccount is a WM5.0 API, and you are using managed code,
> > > why not use the managed equivalent in the WM5.0 SDK -
> > > Microsoft.WindowsMobile.PocketOutlook.MessagingApplication.SwitchToAccount
> > >
> > > With regards your query, if you want to know what the error code is you need
> > > to look at the integer return value from MailSwitchToAccount.
> > >
> > > Peter
> > >
> > > --
> > > Peter Foot
> > > Device Application Development MVP
> > > www.peterfoot.net | www.inthehand.com
> > >
> > > <Groghz(a)gmail.com> wrote in message
> > > news:1161792507.141590.146590(a)i42g2000cwa.googlegroups.com...
> > > > Hi,
> > > >
> > > > I'm pinvoking a mapi function in c#
> > > >
> > > > [DllImport("cemapi.dll", SetLastError = true)]
> > > > public static extern int MailSwitchToAccount(string pszAccount,
> > > > UInt32 dwFlags);
> > > >
> > > > I then call the function :
> > > >
> > > > if (Mapi.MailSwitchToAccount("My_account",
> > > > Mapi.MCF_ACCOUNT_IS_NAME | Mapi.MCF_RUN_IN_BACKGROUND) != 0)
> > > > {
> > > > int err = Marshal.GetLastWin32Error();
> > > > Win32Exception ex = new Win32Exception(err);
> > > > Log("mapi", Severity.Error, "MailSwitchToAccount()
> > > > failed with win32error=" + ex.NativeErrorCode + ", ex.Message=" +
> > > > ex.Message);
> > > > }
> > > >
> > > > The problem is MailSwitchToAccount never returns 0, and so a the error
> > > > handling code is executed. In the logs, the ex.NativeErrorCode is
> > > > always 0, which doesn't seem to be a valid error code.
> > > >
> > > > Is there another way to find the error code ?
> > > >
> > > > regards,
> > > >
> > > > manu
> > > >