WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

IMapiSession exception: Specified cast is not valid

 
   Home -> Office -> Program Add-Ins RSS
Next:  can't create new appointment MSO 2007  
Author Message
skycloud

External


Since: May 11, 2009
Posts: 1



(Msg. 1) Posted: Mon May 11, 2009 5:02 pm
Post subject: IMapiSession exception: Specified cast is not valid
Archived from groups: microsoft>public>outlook>program_addins (more info?)

I'm using Mapi33... trying to get IMapiSession reference using the code
below...

IntPtr iunknownPtr =
Marshal.GetIUnknownForObject(m_OutlookApp.Session.MAPIOBJECT);
IMAPISession imapiSession = (IMAPISession)iunknownPtr;

where m_OutlookApp is an instance of Application from MS.Office.InterOp...

When I run this code inside Outlook via Addin passing m_OutlookApp from
OnConnection... it runs fine,

when I run it from command app, passing an instance of m_OutlookApp using
new Application() I get:

System.InvalidCastException was caught Message="Specified cast is not
valid."

Any idea why or a workaround on how to get an IMapiSession reference from
command line app?

Thanks in advance
Back to top
Login to vote
Dmitry Streblechenko

External


Since: Nov 23, 2003
Posts: 1139



(Msg. 2) Posted: Mon May 11, 2009 8:46 pm
Post subject: Re: IMapiSession exception: Specified cast is not valid [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Did you call MAPIInitialize on that thread?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"skycloud" <skycloud.TakeThisOut@discussions.microsoft.com> wrote in message
news:F2F28A20-3D10-4CDF-B5E4-0EC64440E390@microsoft.com...
> I'm using Mapi33... trying to get IMapiSession reference using the code
> below...
>
> IntPtr iunknownPtr =
> Marshal.GetIUnknownForObject(m_OutlookApp.Session.MAPIOBJECT);
> IMAPISession imapiSession = (IMAPISession)iunknownPtr;
>
> where m_OutlookApp is an instance of Application from MS.Office.InterOp...
>
> When I run this code inside Outlook via Addin passing m_OutlookApp from
> OnConnection... it runs fine,
>
> when I run it from command app, passing an instance of m_OutlookApp using
> new Application() I get:
>
> System.InvalidCastException was caught Message="Specified cast is not
> valid."
>
> Any idea why or a workaround on how to get an IMapiSession reference from
> command line app?
>
> Thanks in advance
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Program Add-Ins All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support